[CMake] static library link order

Bill Hoffman bill.hoffman at kitware.com
Thu Mar 4 10:39:55 EST 2010


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).
> 
The order should be done correctly in target_link_libraries.  If it is 
not, then it is a bug in the CMake code for VTK.   The idea is that each 
library lists its depends in the order that it needs them.  CMake keeps 
track of that order and produces the final link line preserving that 
order.  As for kwsys needing -ldl that is the library loading stuff that 
does that, if you set KWSYS_USE_DynamicLoader to 0, it won't, but VTK 
and ParaView both support loading of dynamic libs.  So, I think you will 
be stuck with that part being dynamic without cutting out code.  So, 
perhaps we need a static linux dashboard for ParaView.  I see a windows 
one, but not a linux one where order matters.  Does ParaView itself not 
link static on linux?

There is not much more CMake can do for this.  So, I would recommend 
moving the discussion to the ParaView or VTK developers list.

-Bill




-- 
Bill Hoffman
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
bill.hoffman at kitware.com
http://www.kitware.com
518 881-4905 (Direct)
518 371-3971 x105
Fax (518) 371-4573


More information about the CMake mailing list