[CMake] static versus shared libraries with BUILD_SHARED_LIBS
James Bigler
bigler at cs.utah.edu
Wed Oct 4 16:15:14 EDT 2006
I'm using CMake 2.4.3 on Linux. When I do:
OPTION(TEEM_BUILD_SHARED_LIBS "Build Teem with shared libraries." OFF)
OPTION(BUILD_SHARED_LIBS ${TEEM_BUILD_SHARED_LIBS})
or
OPTION(BUILD_SHARED_LIBS "Build package with shared libraries." OFF)
and later:
FIND_PACKAGE(PNG)
IF(PNG_FOUND)
ADD_DEFINITIONS(-DTEEM_PNG=1 ${PNG_DEFINITIONS})
SET(TEEM_PNG_LIB ${PNG_LIBRARIES})
SET(TEEM_PNG_IPATH ${PNG_INCLUDE_DIR})
ENDIF(PNG_FOUND)
Now I see in my cmake configuration:
PNG_LIBRARY /usr/lib64/libpng.so
PNG_PNG_INCLUDE_DIR /usr/include
My packages libraries are built static, but I'm pulling in shared
versions of external libraries.
I also have a static version of the library:
libpng-devel /usr/lib64/libpng.a
libpng-devel /usr/lib64/libpng.so
Why did FIND_PACKAGE and eventually FIND_LIBRARY expand this to the full
path and name of the library?
When I look at the build output I see a spurious -rdynamic instead of
-static.
Linking C executable ../../bin/unu
cd /home/sci/bigler/pub/src/teem/octagon/src/bin && /usr/local/bin/cmake
-P CMakeFiles/unu.dir/cmake_clean_target.cmake
cd /home/sci/bigler/pub/src/teem/octagon/src/bin && /usr/bin/gcc -O3
-DNDEBUG -fPIC "CMakeFiles/unu.dir/unu.o" -o ../../bin/unu -rdynamic
-L/home/sci/bigler/pub/src/teem/octagon/bin -L/usr/lib64 -lteem -lbz2
-lz -lpng -lz -lm
-Wl,-rpath,/home/sci/bigler/pub/src/teem/octagon/bin:/usr/lib64
I've verified that if I pass -static instead of -rdynamic it does what I
think it should.
Thanks,
James
More information about the CMake
mailing list