Я использую Android Studio 2.2.2 с cmake и Android NDK. У меня проблема с связыванием библиотеки .a (Static lib).Android NDK Cmake Linking .a (Static) Libs
Вот мой 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: error: cannot find -ltheoraplayer
error: undefined reference to 'TheoraVideoManager::TheoraVideoManager(int)'
, который является частью libtheoraplayer.a. У кого-нибудь была схожая проблема? Любая идея, как это решить?
У меня есть Static lib libtheoraplayer.a, присутствующий в этом месте. У меня даже есть общая библиотека libtheoraplayer.so, но я тоже не могу ее связать.
Любые советы будут оценены.
Cheers.
'У меня есть Static lib libtheoraplayer.a, присутствующий в этом месте.' - Где ** точно ** у вас есть эта библиотека? Я не вижу никаких вызовов 'link_directories' в вашем коде, так почему вы ожидаете, что компоновщик найдет библиотеку? – Tsyvarev
Я новичок в cmake, поэтому, пожалуйста, простите меня, если я задам глупые вопросы. Я использовал старую систему с Android.mk для Android NDK. Я не знаю, что мне нужны link_directories? Lib - уже созданный Theora Player (https://www.theora.org), и мне нужно импортировать его в свой проект. link_directioris должен указывать на исходный файл Theora? –
Вам нужно указать CMake, где он должен искать библиотеку для ссылки. Это можно сделать несколькими способами: используя ** абсолютный путь ** к файлу библиотеки в 'target_link_libraries' или используя * IMPORT * ed ** библиотеку target ** с абсолютным путем или используя вызов 'link_directories' с * каталогом * где искать в библиотеке. Во всех случаях файл библиотеки - 'libtheoraplayer.a', о котором вы говорите в вопросе. – Tsyvarev