cs50 / libcs50

This is CS50's Library for C.
https://cs50.readthedocs.io/libraries/cs50/c/
GNU General Public License v3.0
1.74k stars 853 forks source link

Undefined symbols for architecture x86_64 #215

Closed echorashmi closed 4 years ago

echorashmi commented 4 years ago

I'm trying to run this program:

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

int main(void)
{
    int i = get_int("i: ");
    printf("%i\n", i);
}

It works fine on the CS50 IDE, though on my local Mac I get this error:

Undefined symbols for architecture x86_64:
  "_get_int", referenced from:
      _main in compare-7108b4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [compare] Error 1

How I installed: I followed the instructions from: https://github.com/cs50/libcs50#from-source-linux-and-mac

echorashmi commented 4 years ago

Duplicate, found the resolution here:

https://github.com/cs50/libcs50/issues/123

I was using:

make filename.c

Instead would need to use:

clang -o int int.c -lcs50

Still curious how to get it to work with "make" though.

Rubix982 commented 4 years ago

Hello! This error depends on what you use for a compiler, whether g++ or clang. If you want to use make, simply do make filename without the extension, but the issue with make is that it does not actually link the dynamic libraries ( like cs50 here ). I did a quick search for an option to do that using man make but I can't anything with the keyword link.