in week 1 as I understood : make= compile the file and name the compiled file with the same name. clang= compile the file with the default name. when I've used make it worked and when I used clang it gave me that error:

/tmp/new-9f7660.o: In function `main':
new.c:(.text+0x1c): undefined reference to `get_string'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

the code was :

#include <stdio.h>
#include <cs50.h>

int main(void){
  string name= get_string();
  printf("hi %s\n", name);

1 Answer 1


The make utility actually calls the clang compiler with special options that can be set for a project.

When I run make in the ide it actually runs the following:

clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    temp.c  -lcrypt -lcs50 -lm -o temp

Most of that is unimportant to understand at the moment, but -lcs50 tells clang to link the cs50 library code (the actual code for get_string) with your code so you can call the function.

If you just use clang string.c it won't work, because the actual library code will not be linked. When you #include <cs50.h> that file has a function prototype for all of the functions in the library. Essentially, it is a list of functions that are available to use - but not the actual functions themselves. The lcs50 option is telling clang where those actual functions are.

The first couple of programs in the course used clang to compile, just to show you what the actual compiler program was. Now that we are using cs-50 library functions, you're going to have to use make OR type out the entire clang command from above - which is why someone made the make utility in the first place :) The make utilty is important for MUCH MUCH more than changing the default name of the output file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .