[CMake] Imported libraries and cyclic dependencies

iosif neitzke iosif.neitzke+cmake at gmail.com
Thu Jan 7 21:18:05 EST 2016


Which version of CMake are you using?

On 01/07/2016 04:28 PM, Rainer Poisel wrote:
> Hi,
>
> I am having troubles with linking a bunch of imported libraries that
> have cyclic dependencies.
>
> This is what I am doing:
>
> 8<=======================
> find_library(ESP8266_SDK_LIB_MAIN main ${ESP8266_SDK_BASE}/lib)
> add_library(esp8266_main UNKNOWN IMPORTED)
> set_property(TARGET esp8266_main PROPERTY IMPORTED_LOCATION
> "${ESP8266_SDK_LIB_MAIN}")
>
> find_library(ESP8266_SDK_LIB_PHY phy ${ESP8266_SDK_BASE}/lib)
> add_library(esp8266_phy UNKNOWN IMPORTED)
> set_property(TARGET esp8266_phy PROPERTY IMPORTED_LOCATION
> "${ESP8266_SDK_LIB_PHY}")
>
> find_library(ESP8266_SDK_LIB_PP pp ${ESP8266_SDK_BASE}/lib)
> add_library(esp8266_pp UNKNOWN IMPORTED)
> set_property(TARGET esp8266_pp PROPERTY IMPORTED_LOCATION
> "${ESP8266_SDK_LIB_PP}")
>
> find_library(ESP8266_SDK_LIB_LWIP lwip ${ESP8266_SDK_BASE}/lib)
> add_library(esp8266_lwip UNKNOWN IMPORTED)
> set_property(TARGET esp8266_lwip PROPERTY IMPORTED_LOCATION
> "${ESP8266_SDK_LIB_LWIP}")
>
> target_link_libraries(ESP8266_SDK INTERFACE
>     gcc
>     esp8266_lwip
>     esp8266_main
>     esp8266_phy
>     esp8266_pp
> )
>
> target_link_libraries(esp8266_main INTERFACE
>     esp8266_lwip
>     esp8266_pp
>     esp8266_phy
> )
> 8<=======================
>
> The given example is not complete. However, I hope it is sufficient to
> give you an idea of what I want to achieve: I would like to specify
> the dependencies between imported libraries. Subsequently I want to
> make the linker call mention my libraries several times in order to
> make the linker resolve all dependency cycles (multiplicity).
>
> This is the corresponding error message:
>
> 8<=======================
> CMake Error at external/esp8266-cmake/sdk/nonos-1.4.0.cmake:111
> (target_link_libraries):
> Cannot specify link libraries for target "esp8266_main" which is not built
> by this project.
> 8<=======================
>
> As a workaround I added the -Wl,--start-group (referred to as
> BUILD_LINK_PREFIX) and the -Wl,--end-group (referred to as
> BUILD_LINK_SUFFIX) arguments (yes, it is a GCC) directly to the
> invocation of target_link_libraries() of my executable which has been
> defined by add_executable() beforehand. But I think that this is just
> a botch-up.
>
> Here is an example of the complete code (using the before-mentioned workaround):
>   * https://github.com/rpoisel/esp8266-mqtt
>   * https://github.com/rpoisel/esp8266-cmake/blob/master/main/CMakeLists.txt
>
> Thanks for any suggestions in advance,
>   Rainer
>


More information about the CMake mailing list