Setup · 05
Installing the CS50 library
Put cs50.h on your Mac so helpers like get_string() work with Clang — install from source, fix the paths, optionally wire a Makefile.
17th July 2019
Last updated on 16th August 2026
Author: Kulwinder Krishan

Harvard’s CS50 course gives you friendly helpers like get_string(). Those live in cs50.h — and that header is not part of macOS until you install the library yourself.
If Clang is not on this machine yet, start with Getting your macOS ready for C.
Here is a tiny program that asks for a name and greets you:
cs50-greeting.c
#include <cs50.h>
#include <stdio.h>
int main(void)
{
string name = get_string("Please enter your name here: ");
printf("hello, %s!!\n", name);
return 0;
}
Without the library, the compiler fails hard — cs50.h file not found:
Install from source
Official steps from cs50/libcs50:
- Download the latest release from GitHub Releases.
- Extract the archive and
cdinto the folder. - Run
sudo make install(installs under/usr/localby default).
On older macOS I hit a build snag; the fix that worked for me is in this libcs50 issue comment. Here is the outline:
cs50-pseudocode-step1.c
// go to github.com
// search for cs50 library on the site
// go to cs50/libcs50 webpage there
// download the latest released source code
// extract the source code folder
// go into the source code directory using Terminal
// run "sudo make install" command there
// it will ask for your macOS password
// if everything is correct; cs50 library will get installed
// in macOS Mojave that I have; we have to make changes in the Makefile
// I got error (cp: build/lib/libcs50.dylib: No such file or directory)
// see video below to see the changes made to Makefile
// re-run the "sudo make install" command
What you get
After a successful install you should see:
cs50.hin/usr/local/includelibcs50.dylib(and a versioned sibling) in/usr/local/lib
Compile with Clang and link the library:
clang -lcs50 program.c
cs50-pseudocode-step2.c
// navigate to /usr/local/include to see 'cs50.h' file
// navigate to /usr/local/lib to see 'libcs50-9.0.1.dylib'
// and 'libcs50.dylib' files
// find out that 'libcs50.dylib' is a symbolic link pointing
// to 'libcs50-9.dylib' which does not seem to exist
// go to the folder with the source file that includes cs50.h
// we enter the command
// 'clang -lcs50 program-to-be-compiled.c'
// as described on the github page
// get error 'ld: library not found for -lcs50'
// and 'clang: error: linker command failed with
// exit code 1 (use -v to see invocation)'
Tell Clang where to look
On a Mac, Clang often still cannot find the header or -lcs50 until your shell knows /usr/local. Add these to ~/.zshrc (or ~/.bash_profile if you still use bash):
export C_INCLUDE_PATH=/usr/local/include
export LIBRARY_PATH=/usr/local/lib
Then open a new Terminal window. That matches the troubleshooting notes in the libcs50 README and this issue thread.
cs50-pseudocode-step3.c
// go to /usr/local/lib directory in Terminal
// list the contents of lib/ directory
// notice that 'libcs50.dylib' file is pointing to 'libcs50-9.dylib' file (this file does not exist)
// change the symbolic link so that 'libcs50.dylib' points to 'libcs50-9.0.1.dylib'
// type 'sudo ln -sf libcs50-9.0.1.dylib /usr/local/lib/libcs50.dylib' command and press enter
// enter macOS password
// check by listing the contents of lib/ directory if the symbolic link has changed
// go to the directory where the source code file requiring cs50 library is saved
// run 'clang -lcs50 program-to-be-compiled.c' command
// if the syntax is correct; it will create 'a.out' file
// run './a.out' command to see the output
Optional: a Makefile
If you prefer make over typing -lcs50 every time, drop a Makefile next to your .c file:
makefile.sh
LDLIBS += -lcs50
CC := clang
CFLAGS += -Wall -Wextra -Werror -pedantic -std=c11
Credit: this Stack Overflow answer. Walkthrough:
Without make, the one-liner still works:
cs50-clang-without-make.sh
clang program_to_be_compiled_using_cs50.c -lcs50 -o any_name_you_want_to_give
Next step
Library in place. Time for the classic first program:
Earlier comments(25)
- alex
man i can't say how thankful i am for these videos you helped me out a lot
- Kulwinder Krishan
It's my pleasure, Alex.
Hello, i'm having an issue even after following all 4 steps:
clang -Wall -Wextra -Werror -pedantic -std=c11 hello.c -lcs50 -o hello hello.c:17:2: error: no newline at end of file [-Werror,-Wnewline-eof]
Can you please help me?
- Kulwinder Krishan
Hi Nicholas,
Please enter a newline (empty line) after the last line of code. This will fix your error.
Thanks
- Sergio
Thanks so much! that was so helpful! I just have one more question. Do I have to copy the Makefile in every folder to use make? or how can I fix that? thanks again
- Kulwinder Krishan
You are welcome Sergio!! Yes; you have to copy Makefile in every folder to use make command following the above steps. Unfortunately; I could not figure out how to configure make utility with -lcs50 without the need of creating a Makefile.
- Kevin
I got this error when I tried to configure with the make command: clang -Wall -Wextra -Werror -pedantic -std=c11 hello.c -lcs50 -o hello hello.c:8:2: error: no newline at end of file [-Werror,-Wnewline-eof] } ^ 1 error generated. make: *** [hello] Error 1
- Kulwinder Krishan
Hi Kevin, You can easily fix this error by literally adding a new line by pressing Enter key on your keyboard at the end of file. You can save the file and run make command again and it will execute fine. The reason you get this error is because compiler is nit-picky in following C standards as described at https://gcc.gnu.org/legacy-ml/gcc/2003-11/msg01568.html. Thanks
- juan pablo
i have the same error i have mac os the last version
- Wojtek
Hi, I tried following all your instructions. I get an error:
Starting build... /usr/bin/gcc -fdiagnostics-color=always -g /Users/ws/howareu.c -o /Users/ws/howareu Undefined symbols for architecture arm64: "_get_string", referenced from: _main in howareu-90e59f.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Build finished with error(s).
I don't know what I'm doing wrong.
- Kulwinder Krishan
Hello Wojtek, Can I ask what Operating System (OS) are you using to look into the issue ? Thanks
- Scott
Thank you for the tutorial! What is the "sandbox" that you have in the command line? That threw me off when everything else was working just fine.
- Kulwinder Krishan
Hi Scott, I have named the folder "sandbox" in which I saved source code and executable files. Sandbox is an isolated play area where we can experiment and test code. It is an actual concept in software development as someone has already explained on stack overflow. Thanks
- M1
Hey, thank you for the tutorial! I got this error (I'm using Macbook Pro M1 Pro):
Undefined symbols for architecture arm64: "_get_string", referenced from: _main in first-059bb8.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Best sollution eva
- Diego
Hi im getting an error:
/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/include/stddef.h:103:10: fatal error: '__stddef_max_align_t.h' file not found #include "__stddef_max_align_t.h" ^~~~~~~~~~~~~~~~~~~~~~~~
- Diego
Help Please
I very delighted to find this internet site on bing, just what I was searching for as well saved to fav
very informative articles or reviews at this time.
This was beautiful Admin. Thank you for your reflections.
I like the efforts you have put in this, regards for all the great content.
Good post! We will be linking to this particularly great post on our site. Keep up the great writing
Pretty! This has been a really wonderful post. Many thanks for providing these details.
For the reason that the admin of this site is working, no uncertainty very quickly it will be renowned, due to its quality contents.
You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
Leave a comment
Comments coming soon — set the NEXT_PUBLIC_GISCUS_* env vars after enabling GitHub Discussions and Giscus.