C/cmake - how to add a linker flag to an (unused) library when the library is specified in TARGET_LINK_LIBRARIES?
问题 In the root directory of my project, I have a subdirectory for my_lib and another for my_app . The library my_lib defines tables that populates a section defined by the linker, these tables are not used directly by my_app , so this library is not linked. To force my_lib to be linked I added the flag --whole-archive as described here. And it works! In the CMakelist.txt of the root directory I have the following: SET(CMAKE_EXE_LINKER_FLAGS "-mmcu=cc430f6137 -Wl,--gc-sections -Wl,--whole-archive