[CMake] Link order (Ubuntu)

Bo Zhou bo.schwarzstein at gmail.com
Mon Nov 5 20:16:05 EST 2018


Hi

This is the classical issue of GNU toolchain for many years, usually super
painful when the program has to be linked with several static libraries.

One easy way to solve this issue is that you could specify the same library
for multiple times if the manual order really doesn't work well, then the
generated binary might have the complete symbols.

Thanks very much.

On Tue, Nov 6, 2018 at 9:53 AM scrgiorgio <scrgiorgio at gmail.com> wrote:

> i have the following CMakeList.txt:
>
>
> add_library(ImpLib SHARED IMPORTED GLOBAL)
> set_property(TARGET ImpLib APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES
> ...)
> set_target_properties(ImpLib PROPERTIES IMPORTED_LOCATION ...)
>
> add_library(A SHARED)
> # COMMENTED! A uses ImpLib but cannot link it because some third-party
> executables requires 'run-time symbol resolution'
> # target_link_libraries(A PUBLIC  ImpLib )
>
> add_library(B SHARED)
> target_link_libraries(B PUBLIC A)
> # COMMENTED! B uses ImpLib but cannot link it for the same previous reason
> # target_link_libraries(B PUBLIC  ImpLib )
>
> # my executable requires ImpLib explicit/default cmake linking
> add_executable(MyExe)
> target_link_libraries(MyExe B)
> target_link_libraries(MyExe ImpLib )
>
> The CMake generated link order is (g++ -o .... ): "B;ImportedExtLib;A"
> But in this way A cannot find symbols from ImpLib (at least using g++).
>
> The right order is: "B;A;ImpLib"
>
> I tried with "target_link_libraries(A INTERFACE ImpLib)" but then B will
> link ImpLib
>
> I tried "set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
> -Wl,--start-group")" but sometimes it does not work.
>
> is it doable? Can I force the right order?
>
>
>
>
>
> --
> Sent from: http://cmake.3232098.n2.nabble.com/
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181106/c8dc5dbf/attachment.html>


More information about the CMake mailing list