Android NDK Cmake 链接 .a(静态)库

标签 android android-ndk linker cmake linker-errors

我正在使用带有 cmake 和 Android NDK 的 Android Studio 2.2.2。我在链接 .a 库(静态库)时遇到问题。

这是我的命令:

# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_VERBOSE_MAKEFILE on)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.    
# Gradle automatically packages shared libraries with your APK.  

add_library(lib_webp SHARED IMPORTED )
set_target_properties(lib_webp PROPERTIES IMPORTED_LOCATION
src/main/jni/${ANDROID_ABI}/libwebp.so)


add_library( # Sets the name of the library.
         game-lib

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         # Associated headers in the same location as their source
         # file are automatically included.
         src/main/cpp/main.cpp
         src/main/cpp/android_native_app_glue.c            
         )


target_include_directories(game-lib PRIVATE
 ../../../../libs/headers/android
)

include_directories($ENV{NDK_MODULE_PATH}/sources/android/native_app_glue/)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                   game-lib

                   # Links the target library to the log library
                   # included in the NDK.
                   # ${log-lib}                        


                     # Specifies the name of the NDK library that
                     # you want CMake to locate.
                     log                        
                     android
                     OpenSLES
                     z
                     GLESv2
                     EGL
                     dl                         
                  )

add_definitions(-g -DANDROID -Wno-write-strings -fsigned-char -Wno-conversion-null)

TARGET_LINK_LIBRARIES(game-lib libtheoraplayer.a)

我的链接器报告错误

arm-linux-androideabi/bin\ld: error: cannot find -ltheoraplayer

error: undefined reference to 'TheoraVideoManager::TheoraVideoManager(int)'

它是 libtheoraplayer.a 的一部分。有没有人有类似的问题?知道如何解决这个问题吗?

我在那个位置有静态库 libtheoraplayer.a。我什至还有共享库 libtheoraplayer.so 但我也无法链接它。

如有任何建议,我们将不胜感激。

干杯。

最佳答案

发布答案。正如 Tsyvarev 所说,库的非绝对文件名存在问题。当我使用绝对路径时,它就像一个魅力。

谢谢。 干杯。

关于Android NDK Cmake 链接 .a(静态)库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40358365/

相关文章:

java - 从 EditText 中提取文本并在 TextView 中打印

android - 从 Android 应用程序打开 Whatsapp 联系人列表

android - 在 Android.mk 中为程序集 (.s) 源文件定义一个符号?

linker - 使用 CMake 从静态库链接 Windows DLL 文件,而无需手工制作未解析的符号名称

xcode - 如何使用 make 文件在 Xcode 中编译项目

C++ 使用带有在头文件中定义的全局变量的 C 库

基于当前壁纸的安卓动态壁纸

android - 无法解析 com.google.firebase :firebase-core:10. 2.6

android - Android 上的 getaddrinfo 返回错误 EAI_BADFLAGS

android - 如何在 NDK 项目中的 GL 之上绘制 android UI 元素