Android NDK CMakeLists.txt:错误:未定义引用:

时间:2016-11-10 23:56:10

标签: android android-ndk cmake superpowered

我环顾四周,但我只能找到使用Android.mkApplication.mk的解决方案。我是否正确地认为使用CMakeLists.txt我不需要这些文件?这是我第一次尝试使用Android NDK。

我已将CMakeLists.txtSuperpoweredExample相关联,并且我已调用我的库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
)

堆栈跟踪:

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.

将名称从native-lib更改为nativelib,同样的错误。

我感觉错误在target_link_libraries()的{​​{1}}附近。我正在尝试将我的CMakeLists.txt代码与现有的NativeLib代码相关联。

1 个答案:

答案 0 :(得分:2)

我认为在链接Superpowered示例之前链接您的“nativelib”,因此您的链接器无法找到“nativelib”使用的Superpowered部件。