cs50 / libcs50

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

`make` `hello.c:(.text.startup.main+0xf): undefined reference to `get_int'` #317

Closed danli349 closed 10 months ago

danli349 commented 10 months ago

My source file is hello.c:

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

int main(void)
{   
    int n = get_int("Prompt: ");
    printf("hello world! %d \n", n);
}

I can compile it using gcc hello.c -lcs50 -o hello, and run ./hello successfully.

but I failed to compile it using make hello: the error is

hello.c:(.text.startup.main+0xf): undefined reference to `get_int'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: hello] Error 1

How should I fix it?

dmalan commented 10 months ago

See https://github.com/cs50/cli/blob/caa47904d30674ba2da4de90febc7434e140f079/etc/profile.d/cli.sh#L46-L48!