I am a C noob, so this may be a stupid question. I am trying to compile a .so file (shared library, if I have my terminology correct) of C objects (.o files), for the express purpose of importing them into Python via ctypes. I first compiled the *.so with
gcc -shared -o libvARAM.so ARAM.o ARAM_io.o io.o pre.o rule.o stat.o ART.o vARAM.o
This worked, except that when I tried loading via ctypes I was rewarded with:
OSError: ./libvARAM.so: undefined symbol: max
After some digging, I realized that max is not a standard C function. Calling ldd libvARAM.so informed me that one of the dependencies is libc.so.6. I created a symlink libc.so to libc.so.6 and then tried recompiling my .so as
gcc -shared -o libvARAM.so ARAM.o ARAM_io.o io.o pre.o rule.o stat.o ART.o vARAM.o -llibc
which generated
/usr/bin/ld: cannot find -llibc
The same error is generated if I also try -L/lib/i386-linux-gnu/ -llibc. I am aware of this thread, but feel it is not relevant to my situation, as the solution there is for a makefile. I am using Xubuntu if this matters.
Any help is sincerely appreciated!
One: Linker flags don’t work like that. For
libXYZ.so, the corresponding linker flag is NOT-llibXYZbut only-lXYZ.Two: even this is not needed, as the C standard library (
-lc) is automatically linked to the executable.Three: your problem most likely is that there should be a
max()macro (as opposed to a function) defined in one of the header files, but you don’t include this header file, so the compiler doesn’t know it’s a macro and treats it as a function – thenof course it can’t find it in libc.so because it’s not there.