[CMake] Problem with library link order

Brad King brad.king at kitware.com
Wed Jan 21 15:12:49 EST 2015


On 01/20/2015 12:57 PM, Tom Kacvinsky wrote:
> there are some static archives we build that depend on a third party
> static archive (one we don't build - it comes with the Ada compiler
> we are using), yet the third part archive is on the link line (as
> given by the link.txt file) *before* the static archives we build.

If you have a library

  add_library(mylib STATIC mylib.c)

and it depends on a third-party library then tell CMake so:

  target_link_libraries(mylib otherlib)

Then CMake will guarantee that an occurrence of otherlib appears on
the link line after mylib.

> duplicated shared libraries

These generally don't hurt anything.  CMake 3.1 will de-duplicate
shared libraries that come from logical targets (created via
add_library either as a build target or as an imported library).

> Can anyone point me in the right direction?

FYI, the ordering algorithm is documented in source comments here:

 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmComputeLinkDepends.cxx;hb=v3.1.0#l25

-Brad



More information about the CMake mailing list