[CMake] CMake link order

Bon, William william.bon at caldera.com
Fri Oct 18 06:24:05 EDT 2019


Hello,

we are facing an issue while using cmake and we have no idea how to solve or debug it.
We have a complex and huge project (about 50 subdirectories and dependencies everywhere), and we are facing issue regarding the link order.
There is a lot of dependencies between those projects, and to summarize, we have two libraries A and B
A is an imported library from headers and shared lib .so declared like this
```
add_library(A SHARED IMPORTED GLOBAL)
set_target_properties(A PROPERTIES
        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
        IMPORTED_LOCATION ${A_LIBRARY})
```

B is a system library part of a package.

We need to link A before B in every case.

In every project, we include A before B using
```
find_package(B)
target_link_libraries(${library_produced} PUBLIC A)
target_link_libraries(${library_produced} PUBLIC B)
```

but from time to time, we don't know why, the library produced link in the wrong order (checked with ldd and make VERBOSE=1).
it links B before A.

Is there a way to find out what happens and why cmake change the link order for some project and not all projects ?

Best regards,

Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191018/bc8118ad/attachment-0001.html>


More information about the CMake mailing list