简体   繁体   中英

CMake: link options

I have an Android CMakeList.txt that defines multiple target libararies (static and dynamic). For one of these libraries I need to pass the -Wl,--version-script with a specific version script, to achieve this I'm using target_link_libraries:

target_link_libraries( # Specifies the target library.
        native-lib1
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib}
        -Wl,--version-script=${CMAKE_SOURCE_DIR}/../../../../../../native1.map
        )

Unfortunately the -Wl option is added to all the other libraries I'm targeting causing me any sort of linking issues because native1.map refers to the functions in native-lib1 only. I've also tried to use target_link_options and add_link_options but Android Studio returns error saying these are not valid CMake commands.

Is there a way to define linker options for a single library targeted in CMakeList.txt?

I assume the option is treated as PUBLIC here. In general I recommend always specifying the "visibility" when using target_*** commands.

In this case I'd recommend using target_link_options though, since this states the intention more clearly.

target_link_libraries( # Specifies the target library.
        native-lib1
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib}
        )
target_link_options(native-lib1
    PRIVATE 
        "-Wl,--version-script=${CMAKE_SOURCE_DIR}/../../../../../../native1.map"
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM