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

Getting error like : "Undefined symbols for architecture x86_64" while using get_int #250

Closed doichev-kostia closed 2 years ago

doichev-kostia commented 2 years ago

I am some kind of beginner in programming and absolute beginner in C and I don't know how to troubleshoot such error:

Undefined symbols for architecture x86_64: "_get_int", referenced from: _main in mario-89f3ee.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1

Used CLion IDE from JetBrains as CS50 IDE was loading extremely long.

I installed cs50 library as It was written on README. However, when I was trying to connect it using #include and used get_int function, I got an error that I mentioned above.

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

void draw(int h);

int main(void) {

    int height = get_int("Height: ");
    draw(height);

    return 0;
}

void draw(int h) {
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= i; j++) {
            printf("#");
        }
        printf("\n");
    }
}

picture of error

doichev-kostia commented 2 years ago

This error don't show when I use such command clang -o mario mario.c -lcs50. However, it shows while using make mario. Can someone explain to me what is the difference, please?

abdulsalamahasan commented 2 years ago

I kinda faced same error, while using make it showed up, but with clang it does not.

I believe it has something to do with the header file and the installation of it. I use Linux Ubuntu, I will check it again and notify you if I find a solution for it.

doichev-kostia commented 2 years ago

Maybe it's something connected with this prefix -lcs50

dmalan commented 2 years ago

On CS50 IDE, CS50 configures make with these defaults, using environment variables!

https://github.com/cs50/cli/blob/main/etc/profile.d/cli.sh#L57-L59

doichev-kostia commented 2 years ago

Thanks a lot