Robert Bielik wrote:
Ok, apologies if this is already implemented, just haven't seen it.

When making "Unix Makefiles", then link.txt script have archive files (static libraries) listed in the
order they appear in the TARGET_LINK_LIBRARIES directive.

The GCC linker (LD) has the peculiarity that if symbols are defined in library A and library B needs them, but B is given on the LD command line after library A, linking will fail with unresolved dependencies.

LD supports the directive --start-group/--end-group to get around this issue, see (http://sourceware.org/binutils/docs/ld/Options.html#Options)

Question is then: Can I direct CMake to enclose static libraries on the command line of LD with --start-group/--end-group?

Flags can be passed to target_link_libraries too:

  add_library(A STATIC a.c)
  add_library(B STATIC b.c)
  add_executable(main main.c)
  target_link_libraries(main -Wl,--start-group A B -Wl,--end-group)

CMake 2.6 also supports circular dependencies for static libraries:

  add_library(A STATIC a.c)
  add_library(B STATIC b.c)
  target_link_libraries(A B)
  target_link_libraries(B A)
  add_executable(main main.c)
  target_link_libraries(main A)

The link line will contain

 ... -o main libA.a libB.a libA.a libB.a

This works in most cases, although it is possible to construct
pathological dependencies that require more than one repeat.  In that
case you can repeat "A B A B A B" in the target_link_libraries command
and CMake will honor it.  However, if the archives are really that
inter-dependent then IMO they should be just one archive.

-Brad
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to