"undefined symbol" when trying to compile c?
hello, i been having this problem for about a week now, and i cant seem to find out how to fix it
whenever i try to compile a c program, the linker gives that "undefined symbol" stuff i have 2 separate small projects i tried to compile, one just be trying to learn how to use the xml library, and the other is a multi file c program just for fun, both compile fine with only some small warnings, the usually stuff like "inter to pointer without a cast" or ignorable stuff like that ... all the problem come at compile time, and its always the linker giving that undefined symbol stuff, and it only does that to included files for some reason ... anyways, heres the output from the xml one (just because thats smallest) Code:
gcc -o test filetypes.c -I/usr/include/libxml2 -L/usr/lib -lxml -lz Code:
filetypes.c: In function `filetypearraycreater': Code:
#include <libxml/xmlmemory.h> |
That's a linker problem that most likely indicates that the
file you're trying to link against (libxmls.so) is NOT in /usr/lib but tucked away somewhere else. I don't know where it would live in gentoo, in Slack 10 libxml.so is not present at all (by default) libxml2 is used. Cheers, Tink |
You have wrong library name.
Code:
gcc -o test filetypes.c -I/usr/include/libxml2 -L/usr/lib -lxml2 -lz |
thanks ToniT, it was the wrong library name *curses the xml-config that said to use -lxml* ...... but what could be the cause of the same errors in the other program i had?.... i know it wasn't a wrong lib's name, all the errors in linking came from trying to use functions i made,, or in same cases variables ... am i supposed to add "-I" or "-l" options to use those functions and variables ..?
|
That depends on HOW you compiled the various bits
and pieces ... You should be able to do: gcc -c file1.c -o my1.o gcc -c file2.c -o my2.o gcc -c file3.c -o my3.o gcc -o test main.c my1.o my2.o my3.o for instance ... Cheers, Tink |
sorry, i haven't responded in a while, i haven't been at my computer for some time
.. anyways, i did the compile the exact same way you showed above Tinkster, no compile errors, some warnings (i fix them later i guess) .. but when its time for the linker to do its think, all i get is "undefined" functions and variables (they were defined in the .h files, the compiler didn't mind them) ... any ideas?, or do i need to include something else to get it to want to work? |
Quote:
Functions are *not* defined in header files, but only declared, meaning your C code knows about their name, return value and parameters count and type to verify you use it the proper way. Functions *are* defined either in libraries, that can be either object (.o) or shared objects files (.so), and are linked with your own objects to build the executable binary. You can find out if the function you need is present in the xml2 library by using the command: Code:
nm -D /usr/lib/libxml2.so | grep xmlSaveFormatFile |
All times are GMT -5. The time now is 05:45 AM. |