I have a circular dependency between the two static libraries libA
and libB
:
add_library(LibA STATIC a.c)
add_library(LibB STATIC b.c)
# Circular dependency: LibA <-> LibB
target_link_libraries(LibA PRIVATE LibB)
target_link_libraries(LibB PRIVATE LibA)
add_executable(Example main.c)
target_link_libraries(Example PRIVATE LibA LibB)
When generating the build configuration CMake tries to resolve these dependencies by passing LibA
and LibB
twice each to the linker:
ilinkarm.exe --silent CMakeFiles\Example.dir\main.c.o LibA.lib LibB.lib LibA.lib LibB.lib -o Example.exe
However the IAR linker I use already does multiple passes through the list of libraries and it would be sufficient if LibA
and LibB
are only listed once. Linking with the duplications does still work, but I get the following warnings:
[build] Warning[Li065]: duplicate file: "LibA.lib"
[build] Warning[Li065]: duplicate file: "LibB.lib"
Is there a possibility to tell CMake that every library in the linker command has to be unique even with circular dependencies?
I tried setting CMAKE_C_LINK_EXECUTABLE
but I couldn't find an alternative to <LINK_LIBRARIES>
which already seems to contain the duplicates. That's why this line results in the same warning:
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
CMake version: 3.26.3
Ninja version: 1.10.2
IAR version: 9.32.2