I am trying to replicate CS50x's sandbox on my Gentoo system, but I am getting this kind of error when running make
% make price
cc price.c -o price
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cc9TASaL.o: in function `main':
price.c:(.text+0x15): undefined reference to `get_float'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: price] Error 1
For reference, this is the source file:
% cat price.c
#include <stdio.h>
#include <cs50.h>
int main(void)
{
float price = get_float("What's the price?\n");
printf("Your total is %.2f (VAT included)\n", price * 1.22);
}
I have manually installed libcs50 on my system:
# ldconfig -p | grep cs50
libcs50.so.10 (libc6,x86-64) => /usr/local/lib64/libcs50.so.10
libcs50.so (libc6,x86-64) => /usr/local/lib64/libcs50.so
And when I compile the file with
% gcc -lcs50 price.c -o price
I am getting no errors.
Have I configured something wrong on my system, or have I misunderstood how make
works?
After watching the lecture, I was under the impression that make
would "automagically" add the -lcs50
parameter.
Thanks!
SOLUTION
Set CC
, CFLAGS
and LDLIBS
according to these instructions: https://cs50.readthedocs.io/libraries/cs50/c/ .
All the "automagical" stuff in the lecture videos is possible thanks to those environment variables.