[CMake] Link order (Ubuntu)

scrgiorgio scrgiorgio at gmail.com
Mon Nov 5 19:52:58 EST 2018


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/


More information about the CMake mailing list