Android NDK Cmake链接.a(静态)库 [英] Android NDK Cmake Linking .a (Static) Libs

查看:441
本文介绍了Android NDK Cmake链接.a(静态)库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Android Studio 2.2.2与cmake和Android NDK结合使用.我在链接.a库(静态库)时遇到问题.

I am using Android Studio 2.2.2 with cmake and Android NDK. I have a problem linking .a library (Static lib).

这是我的cmake:

# 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:错误:找不到-ltheoraplayer

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

错误:对'TheoraVideoManager :: TheoraVideoManager(int)'的未定义引用

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

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

which is a part of libtheoraplayer.a. Did anyone had similar problem? Any idea how to solve this?

我在该位置上有静态库libtheoraplayer.a.我什至也有共享库libtheoraplayer.so,但是我也无法链接它.

I have the Static lib libtheoraplayer.a present at that location. I even have the Shared lib also, libtheoraplayer.so but I can`t link it either.

任何建议将不胜感激.

干杯.

推荐答案

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

To post the answer. As Tsyvarev said, the problem with non-absolute file name for library. When I used absoulte path it worked like a charm.

谢谢. 干杯.

这篇关于Android NDK Cmake链接.a(静态)库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆