[CMake] Problem linking static lib into shared lib on Linux
Andreas Pakulat
apaku at gmx.de
Wed Mar 18 16:03:12 EDT 2009
On 18.03.09 11:31:13, Eric Lemings wrote:
> When I try to link a static library into a shared library on SUSE Linux
> 11, I get the following link error:
>
> /usr/bin/c++ -fPIC -shared -Wl,-soname,libbar.so -o libbar.so
> CMakeFiles/shared_bar_lib.dir/Bar.cpp.o
> CMakeFiles/shared_bar_lib.dir/__/__/include/moc_Bar.cxx.o
> -L/my/build/path/archive -L/my/build/path/runtime -lfoo -lQtGui -lpng
> -lSM -lICE -lXi -lXrender -lXrandr -lXcursor -lXinerama -lXfixes
> -lfreetype -lfontconfig -lXext -lX11 -lm -lQtCore -lz -lrt -lpthread
> -ldl -Wl,-rpath,/my/build/path/archive:/my/build/path/runtime
> /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld:
> /my/build/path/archive/libfoo.a(modules.cpp.o): relocation
> R_X86_64_32 against `a local symbol' can not be used when making a
> shared object; recompile with -fPIC
> /my/build/path/archive/libfoo.a: could not read symbols: Bad value
> collect2: ld returned 1 exit status
> make[2]: *** [library/Bar/libbar.so] Error 1
>
> Is this a problem with CMake or am I doing something wrong?
You're doing something wrong, linking static libs into shared libs is not
supported on all platforms. You can make it work in on linux/x86-64 by
passing -fPIC when compiling the static lib (or was it the shared lib),
however this might not work on other platforms.
Andreas
--
You're being followed. Cut out the hanky-panky for a few days.
More information about the CMake
mailing list