I'm attempting to use a C library for an opencourseware course from Harvard. The instructor's instructions for setting up the external lib can be found here.
I am following the instructions specific to ubuntu as I am trying to use this lib on my ubuntu box. I followed the instructions on the page to set it up, but when I run a simple
printf("What do you want to say to the world?\n");
string message = GetString();
$ gcc helloWorld.c
/tmp/ccYilBgA.o: In function `main':
helloWorld.c:(.text+0x16): undefined reference to `GetString'
collect2: ld returned 1 exit status
First, as a beginner, you should always ask GCC to compile with all warnings and debugging information enabled, i.e.
gcc -Wall -g
Then you are probably missing some Harvard specific library, some options like
-L followed by a library directory, then
-l glued to the library name. So you might need
gcc -Wall -g -lcs50 (replace
cs50 by the appropriate name) and you might need some
Notice that the order of program arguments to
gcc is significant. As a general rule, if
a depends upon
b you should put
b; more specifically I suggest
gccprogram name; add the C standard level eg
-Wall -g(you may even want to add
-Wextrato get even more warnings).
libbb.so, in that order)
-o your-program-nameto give the name of the produced binary. Don't use the default name
Directory giving options
-I (for preprocessor includes) and
-L for libraries can be given several times, order is significant (search order).
Very quickly you'll want to use builder tools like
Learn also to use the debugger
Get the habit to always ask for warnings from the compiler, and always improve your program till you get no warnings: the compiler is your friend, it is helping you!