Android NDK error when linking shared C library

前端 未结 1 1415
难免孤独
难免孤独 2020-12-21 23:06

I\'m trying to link some C files to an NDK project that I\'m working on, and set my CMakeLists.txt file up like below.

cmake_minimum_required(VE         


        
相关标签:
1条回答
  • 2020-12-21 23:49

    I think you misunderstand the cmake syntax. Below is enough for your case.

    target_link_libraries(
        main
        ${log-lib})
    

    Below are source files, NOT library names.

    communication_api
    cybtldr_api
    cybtldr_parse
    cybtldr_command
    

    So, you cmake statements are not correct.

    If you want to make less confusing, try to make below changes.

    find_library( # Sets the name of the path variable.
            log-lib
            log)
    
    
    add_library( # Specifies the name of the library.
            my-native-lib SHARED
            main.c
            communication_api.c
            cybtldr_api.c
            cybtldr_parse.c
            cybtldr_command.c
            )
    target_link_libraries(my-native-lib
            ${log-lib})
    

    But, remember to change your Java side as well, see below example:

    // Used to load the 'my-native-lib' library on application startup.
    static {
        System.loadLibrary("my-native-lib");
    }
    

    I just enclose my JniExample project in case you need: https://github.com/russell-shizhen/JniExample

    0 讨论(0)
提交回复
热议问题