Static link with shared libraries

Asked by Paolo Crosetto

Hi,
when linking I get an error, because CMake tries to link statically shared libraries. For example it adds to the link line
/the/path/libarmadillo.so
instead of
-L/the/path -larmadillo
Does anybody know why?
Thanks

Paolo

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johannes Ring
Solved:
Last query:
Last reply:
Revision history for this message
Johannes Ring (johannr) said :
#1

That is how CMake (>=2.6) implements linking. It passes /path/to/libfoo.so directly to the linker as a path instead of using -L/path/to -lfoo.

What is the error message you get?

Revision history for this message
Paolo Crosetto (p-crosetto) said :
#2

Hi, thank you for your answer.
I have the following problem: compiling with IBM XL compilers and linking shared libraries to build an executable I should use the linker flags "-qnostaticlink -qnostaticlink=libgcc".
I could modify the linker flags (settng CMAKE_SHARED_LINKER_FLAGS) to build dolfin, and everything looks fine. But when I try to build a demo the link line is without those flags, and the linking fails with the error below...

cd /homea/slfse/slfse05/src/fenics/dolfin-1.0.0/demo/pde/mixed-poisson/cpp && /usr/local/cmake/bin/cmake -E cmake_link_script CMakeFiles/demo_mixed-poisson.dir/link.txt --verbose=1
/bgsys/drivers/ppcfloor/comm/xl/bin/mpicxx -I/usr/include -I/usr/include -O -DNDEBUG CMakeFiles/demo_mixed-poisson.dir/main.cpp.o -o demo_mixed-poisson -L/bgsys/local/boost/1.47.0/lib -L/bgsys/drivers/V1R1M2/ppc64/comm/sys/lib -L/bgsys/drivers/toolchain/V1R1M2/gnu-linux/powerpc64-bgq-linux/lib /homea/slfse/slfse05/local/lib/fenics/lib/libdolfin.a -lxml2 /homea/slfse/slfse05/local/lib/armadillo/lib/libarmadillo.so -lboost_filesystem-mt-1_47 -lboost_program_options-mt-1_47 -lboost_system-mt-1_47 -lboost_thread-mt -lboost_iostreams-mt -lboost_math_tr1-mt-1_47 -lboost_mpi-mt-1_47 -lboost_serialization-mt-1_47 -lz /bgsys/drivers/V1R1M2/ppc64/comm/xl/lib/libcxxmpich.a /bgsys/drivers/V1R1M2/ppc64/comm/xl/lib/libmpich.a /bgsys/drivers/V1R1M2/ppc64/comm/xl/lib/libopa.a /bgsys/drivers/V1R1M2/ppc64/comm/xl/lib/libmpl.a -lpami /bgsys/drivers/V1R1M2/ppc64/spi/lib/libSPI.a /bgsys/drivers/V1R1M2/ppc64/spi/lib/libSPI_cnk.a -lpthread /bgsys/drivers/toolchain/V1R1M2/gnu-linux/powerpc64-bgq-linux/lib/librt.so /bgsys/drivers/toolchain/V1R1M2/gnu-linux/powerpc64-bgq-linux/lib/libstdc++.so -Wl,-rpath,/homea/slfse/slfse05/local/lib/armadillo/lib:/bgsys/local/boost/1.47.0/lib:/bgsys/drivers/V1R1M2/ppc64/comm/sys/lib:/bgsys/drivers/toolchain/V1R1M2/gnu-linux/powerpc64-bgq-linux/lib/bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/bin/ld: cannot find -lxml2
/bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/bin/ld: attempted static link of dynamic object `/homea/slfse/slfse05/local/lib/armadillo/lib/libarmadillo.so'
make[2]: *** [demo/pde/mixed-poisson/cpp/demo_mixed-poisson] Error 1

Revision history for this message
Best Johannes Ring (johannr) said :
#3

This might be a bug, but the CMAKE_SHARED_LINKER_FLAGS is not propagated to dolfin-config.cmake and dolfin.pc. Try adding the linker flags in DOLFIN_LINK_FLAGS or CMAKE_EXE_LINKER_FLAGS instead.

Revision history for this message
Paolo Crosetto (p-crosetto) said :
#4

Thanks, defining these 2 variables solved that problem

Revision history for this message
Paolo Crosetto (p-crosetto) said :
#5

Thanks Johannes Ring, that solved my question.