0

On Ubuntu 14.10, how to automatically link cs50.h when using make, without needing to link it manually like with GCC.

I need to make cs50 link automatically when I call make on my c file.

When I use "make ages", I get the following error.

cc     ages.c   -o ages
/tmp/ccq2ouVM.o: In function `main':
ages.c:(.text+0x30): undefined reference to `GetInt'
ages.c:(.text+0xc7): undefined reference to `GetInt'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'ages' failed
make: *** [ages] Error 1

1 Answer 1

3

cs50.h is a header file. Header files are NOT linked. They are included. What is linked is a library binary file.

If you have successfully installed the cs50 library according to the instructions here, then follow these steps to link it by default when executing make

  1. open up a terminal window (Ctrl + Alt + T)
  2. change directories to your home directory by executing cd (if you're not there already)
  3. execute gedit .bashrc
  4. at the end of the file add

    export LDLIBS=-lcs50
    
  5. save the file and exit
  6. close the current terminal window and open a new one or just execute . .bashrc (in the current one) and try using make

For more information about which variables that make uses for its implicit rules, see this!

9
  • thanks worked perfectly. :)
    – Anjan
    Commented Feb 24, 2015 at 14:37
  • Hi I reinstalled my OS now 14.10 Ubuntu, Now after following all these steps. I get the following error. ages.c:(.text+0x30): undefined reference to `GetInt'
    – Anjan
    Commented Mar 6, 2015 at 11:39
  • @Anjan what does the compilation command that executes when you execute make <program name> look like?
    – kzidane
    Commented Mar 6, 2015 at 12:55
  • I use "make ages" to complie and then i get the following error. /tmp/ccq2ouVM.o: In function main': ages.c:(.text+0x30): undefined reference to GetInt' ages.c:(.text+0xc7): undefined reference to `GetInt' collect2: error: ld returned 1 exit status <builtin>: recipe for target 'ages' failed make: *** [ages] Error 1
    – Anjan
    Commented Mar 8, 2015 at 9:10
  • Have edited the original question please have a look @Kareem
    – Anjan
    Commented Mar 8, 2015 at 9:20

You must log in to answer this question.

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