Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just wanted to add a c library to Ubuntu which was created by Harvard University for cs50 course. They provided instructions for how to install the library which is listed below.

Debian, Ubuntu

First become root, as with:

sudo su -

Then install the CS50 Library as follows:

apt-get install gcc
rm -f
cd cs50-library-c-3.1
gcc -c -ggdb -std=c99 cs50.c -o cs50.o
ar rcs libcs50.a cs50.o
chmod 0644 cs50.h libcs50.a
mkdir -p /usr/local/include
chmod 0755 /usr/local/include
mv -f cs50.h /usr/local/include
mkdir -p /usr/local/lib
chmod 0755 /usr/local/lib
mv -f libcs50.a /usr/local/lib
cd ..
rm -rf cs50-library-c-3.1

I did exactly as directed. But the compiler reported “Undefined reference to a function”--the function was Get String. So, I searched for a solution and found one. It said to use the -l switch.

Now when I compile I use something like:

gcc –o hello.c hello –lcs50

(I don’t remember the exact command.)

However, I cannot use the make command, which is easier to use.

I understand that there is some problem with linking the library. What is a good solution to this problem?

share|improve this question
Please reproduce the error and provide all the output of the command that produces the errors (including non-error output, if any) by editing your question. While editing your question, paste it in, select it, and use the <$> tool in the Ask Ubuntu editing toolbar to make it appear correctly. – Eliah Kagan Jun 26 '12 at 23:11

I am taking CS50 as well, and I have the same problem. After following Cs50's instructions, I get this error when compiling code using gc

/tmp/ccvUiSKS.o: In function `main':
Goodmario.c:(.text+0x21): undefined reference to `GetInt'
collect2: error: ld returned 1 exit status

I have followed the instructions to the exact. I believe that you should just continue using -lcs50, it's not any harder. eg. The command I use to compile a program

gcc Goodmario.c -o Goodmario -std=c99 -lcs50

Not very hard : D

share|improve this answer

you should add the following command to make GetInt work:

$ gcc hello.c -I/usr/local/include -L/usr/local/lib -lcs50 -o hello

rename "hello.c# and "hello" with your input file and your desired output name. The option -I/usr/local/include tells gcc to also look in /usr/local/include for header files. The option -L/usr/local/lib tells gcc (in the linking phase) to also look for libraries in /usr/local/lib, and the option -lcs50 tells gcc which libraries you need.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.