[CMake] static library link order
Michael Wild
themiwi at gmail.com
Thu Mar 4 10:11:03 EST 2010
On 4. Mar, 2010, at 15:56 , Biddiscombe, John A. wrote:
> given a config like this
>
> TARGET_LINK_LIBRARIES(${KIT}CxxTests vtkIO vtkImaging vtksys)
>
> I have the trouble that vtksys pulls in a whole bunch of DynamicLoader stuff (kwsys) - which apart from being rather odd when building statically, forces the linker to need -ldl added to the link line.
>
> The trouble I've got is that no matter which EXE_LINKER_FLAG etc, or other option I change, TARGET_LINK_LIBRARIES adds stuff to the end, and on linux, link order is important, so I am constantly having to manually edit cmake/make files to get stuff to link (libdl, libGL, libmpich, lib etc etc). This problem is a big one in the whole paraview build system.
>
> Is there any simple fix out there? (NB. It's not just libdl, but many others like it).
>
> JB
>
>
> --
> John Biddiscombe, email:biddisco @ cscs.ch
> http://www.cscs.ch/
> CSCS, Swiss National Supercomputing Centre | Tel: +41 (91) 610.82.07
> Via Cantonale, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
Yep, static linking is a PITA and I don't think it can be correctly done in a fully automatic fashion since CMake has no way of determining the dependencies.
If you are using Linux, you can try to modify the CMAKE_CXX_LINK_EXECUTABLE, CMAKE_CXX_CREATE_SHARED_LIBRARY and CMAKE_CXX_CREATE_SHARED_MODULE variables (possibly also for other languages) such that the <LINK_LIBRARIES> part is enclosed in --start-group and --end-group which causes the linker to iterate the libraries until no more symbols can be resolved. Obviously this comes with a significant increase in linking-time...
HTH
Michael
More information about the CMake
mailing list