我環顧四周,但我只能找到使用Android.mk
和Application.mk
的解決方案。我是否認爲通過使用CMakeLists.txt
我不需要這些文件?這是我第一次嘗試使用Android NDK。Android NDK CMakeLists.txt:錯誤:未定義的參考:
我已將我的CMakeLists.txt
關閉爲SuperpoweredExample
,我已撥打我的圖書館nativelib
。看起來,.cpp文件無法在頭文件中找到引用。難道我做錯了什麼?它構建得很好,但它只是在編譯時引發這些錯誤。
的CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
# 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(# Sets the name of the library.
nativelib
# 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.
G:/Git/NDKTest/app/src/main/jni/nativelib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library(# Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# 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.
nativelib
# Links the target library to the log library
# included in the NDK.
${log-lib})
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Below here is copy and pasted from the SuperpoweredExample
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
set(
PATH_TO_SUPERPOWERED
"C:/Users/j/Downloads/Superpowered/Superpowered"
)
message(${ANDROID_ABI})
file(GLOB CPP_FILES "*.cpp")
add_library(
SuperpoweredExample
SHARED
${CPP_FILES}
${PATH_TO_SUPERPOWERED}/AndroidIO/SuperpoweredAndroidAudioIO.cpp
)
include_directories(src/main/jni)
include_directories(${PATH_TO_SUPERPOWERED})
target_link_libraries(
SuperpoweredExample
log
android
OpenSLES
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
nativelib
)
堆棧跟蹤:從nativelib
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing 'G:\sdk1\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build G:\Git\NDKTest\app\.externalNativeBuild\cmake\debug\x86 --target nativelib}
[1/2] Building CXX object CMakeFiles/nativelib.dir/nativelib.cpp.o
[2/2] Linking CXX shared library G:\Git\NDKTest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so
FAILED: cmd.exe /C "cd . && G:\sdk1\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target i686-none-linux-android -gcc-toolchain G:/sdk1/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=G:/sdk1/ndk-bundle/platforms/android-16/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fsigned-char -Inull -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnativelib.so -o G:\Git\NDKTest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so CMakeFiles/nativelib.dir/nativelib.cpp.o -llog -lm "G:/sdk1/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a" && cd ."
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:16: error: undefined reference to 'SuperpoweredRoll::SuperpoweredRoll(unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:17: error: undefined reference to 'SuperpoweredFilter::SuperpoweredFilter(SuperpoweredFilterType, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:18: error: undefined reference to 'SuperpoweredFlanger::SuperpoweredFlanger(unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:19: error: undefined reference to 'SuperpoweredRecorder::SuperpoweredRecorder(char const*, unsigned int, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:21: error: undefined reference to 'SuperpoweredAndroidAudioIO::SuperpoweredAndroidAudioIO(int, int, bool, bool, bool (*)(void*, short*, int, int), void*, int, int, int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:28: error: undefined reference to 'SuperpoweredRecorder::stop()'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:30: error: undefined reference to 'SuperpoweredRecorder::start(char const*)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:37: error: undefined reference to 'SuperpoweredRecorder::process(float*, float*, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:38: error: undefined reference to 'SuperpoweredFloatToShortInt(float*, short*, unsigned int, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:43: error: undefined reference to 'SuperpoweredAndroidAudioIO::~SuperpoweredAndroidAudioIO()'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:44: error: undefined reference to 'SuperpoweredRecorder::~SuperpoweredRecorder()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
改名爲nativelib,同樣的錯誤。
我有一種感覺,錯誤是在target_link_libraries()
的CMakeLists.txt
。我正在嘗試將我的NativeLib
代碼與現有的SuperpoweredExample
代碼鏈接起來。
這是一個編譯器錯誤。你確定提供所有包含嗎?手動輸入編譯命令是否編譯?那麼你可能想把你的命令與CMake的命令進行比較(使用VERBOSE = ON) – usr1234567