2016-11-01 50 views
4

私はAndroidスタジオ2.2.2をcmakeとAndroid NDKで使用しています。 .aライブラリ(静的ライブラリ)をリンクする際に問題があります。Android NDK Cmake .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) 

私のリンカはlibtheoraplayer.aの一部であり、エラー

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

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

を報告します。

は、ここに私のcmakeのです。誰も同じような問題を抱えていましたかどのようにこれを解決するための任意のアイデア?

私はその場所に静的ライブラリlibtheoraplayer.aを持っています。私も共有ライブラリlibtheoraplayer.soを持っているが、私はそれもリンクすることはできません。

アドバイスをいただければ幸いです。

乾杯。

+0

'静的ライブラリlibtheoraplayer.aがその場所にあります。 ' - **正確に**このライブラリはありますか?私はあなたのコードで 'link_directories'呼び出しを見ないので、リンカがライブラリを見つけるのはなぜですか? – Tsyvarev

+0

私はcmakeの新人ですので、私は愚かな質問をする場合は私を許してください。 Android NDKのAndroid.mkで古いシステムを使用しました。私はlink_directoryが必要であることに気づいていませんか? libはすでに構築されているTheora Player(https://www.theora.org)で、プロジェクトにインポートする必要があります。 link_directiorisはTheoraのソースファイルを指すはずですか? –

+0

あなたはリンクを探すためにライブラリを検索する場所をCMakeに指示する必要があります。 'target_link_libraries'のライブラリファイルに**絶対パス**を使うか、絶対パスで* IMPORT * ed **ライブラリターゲット**を使うか、*ディレクトリ*で 'link_directories'コールを使用して**絶対パス**を使用する方法があります。ライブラリを検索する場所。すべての場合、ライブラリファイルは 'libtheoraplayer.a'です。これはあなたが質問で言及します。 – Tsyvarev

答えて

3

回答を投稿するにはTsyvarevが言ったように、ライブラリの絶対ファイル名ではない問題。私がアブール・パスを使用したとき、それは魅力のように働いた。

ありがとうございます。 乾杯。

関連する問題