-
Linker Error Help
Hi Everyone,
In general what is the following linker error indicating?
/app/lib/libXyz.so: undefined reference to `some_symbol'
Using g++ compiler on Linux.
I get multiple of these all with the same .so file but different undefined reference to part.
I need help understanding the general meaning of this and maybe a link to something expalining the Linux build process.
Thanks.
-
Re: Linker Error Help
.so is a shared library, similar to .dll on windows. The linker is trying to find the .so file and cant find it. You need to make sure you have the file, and it is also where the linker expects to find it.
-
Re: Linker Error Help
Do you mean the linker is trying to find libXyz.so or the .so that the some_symbol is defined in?
Thanks for your help.
-
Re: Linker Error Help
One of two things is happening. Either the linker cannot find the .so file, or else it finds it but the .so file doesn't export the functions you have used. So either you have a missing .so file or perhaps a wrong version .so file.
-
Re: Linker Error Help
Libraries usually depend on other libraries. Let's say libxyz.so depends on libz.so you have to specify both libraries when linking (g++ -o prog *.o -lxyz -lz).
If you do not specify all libraries, the linker will complain that symbols referenced in libxyz cannot be found. You can use the ldd command to understand what libraries libxyz.so depends on:
Code:
treuss>ldd /usr/lib/libpng12.so.0
libz.so.1 => /usr/lib/libz.so.1 (0xb7fa6000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7f7f000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e3d000)
So libpng12 depends on libz (and the standard libraries libc and libm).