Wenzhe
Wenzhe

Reputation: 95

How to set version-script file in CMakeLists.txt file of Android Studio

I have a ndk project in Android Studio, and I want to control the exported symbols by this way:

set (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--version-script=D:\\ProjectFolder\\export_symbols")

or

set (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--version-script=export_symbols")

This export_symbols file is put together with CMakeLists.txt. The problem is that the compiler would report an error during link and complain that: 'error: no such file or directory'.

So the question is how can I tell the compiler where my export_symbols file is? Any suggestion is welcomed. Thanks.

Upvotes: 5

Views: 5106

Answers (2)

Sheikh
Sheikh

Reputation: 1146

Try to do next:

  1. Find you add_library command. E.g.:

    add_library( ${MY_LIBRARY_NAME} SHARED main.cpp )
    
  2. And right after it add set_target_properties command:

    set_target_properties( ${MY_LIBRARY_NAME} PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../your_version.script)
    

Here is short info about LINK_DEPENDS.

Upvotes: 2

Wenzhe
Wenzhe

Reputation: 95

Solved by adding ${CMAKE_SOURCE_DIR} before the file name.

set (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-Wl,--version-script=" ${CMAKE_SOURCE_DIR} "/export_symbols")

Upvotes: 2

Related Questions