How to install custom c library?
- by arijit
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
wget http://mirror.cs50.net/library/c/cs50-library-c-3.1.zip
unzip cs50-library-c-3.1.zip
rm -f cs50-library-c-3.1.zip
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?