简体   繁体   English

Android NDK.Build 命令失败。 未定义参考。 clang++:错误:linker 命令失败,退出代码为 1

[英]Android NDK.Build command failed. Undefined reference. clang++: error: linker command failed with exit code 1

I am getting this error when I try to make separate libraries, with add_library(mycpp-lib...) and add_library(native-lib...) .当我尝试使用add_library(mycpp-lib...)add_library(native-lib...)创建单独的库时出现此错误。 When I build using single add_library() , I do not get the error.当我使用单个add_library()构建时,我没有收到错误。

Note: Both libraries ( libmycpp-lib.so and libnative-lib.so ) are generated successfully.注意:两个库( libmycpp-lib.so 和 libnative-lib.so )都已成功生成。

This is the error I am getting:这是我得到的错误:

Build command failed.
Error while executing process /Users/vk/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/vk/Development/MyNativeApp1/app/.cxx/cmake/debug/arm64-v8a mycpp-lib native-lib}
ninja: Entering directory `/Users/vk/Development/MyNativeApp1/app/.cxx/cmake/debug/arm64-v8a'
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so 
: && /Users/vk/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/vk/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/vk/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  -llog -latomic -lm && :
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o: In function `Java_vikas_example_com_mynativeapp1_MainActivity_stringFromJNI':
/Users/vk/Development/MyNativeApp1/app/.cxx/cmake/debug/arm64-v8a/../../../../src/main/cpp/native-lib.cpp:14: undefined reference to `addtwo(int, int)'
/Users/vk/Development/MyNativeApp1/app/.cxx/cmake/debug/arm64-v8a/../../../../src/main/cpp/native-lib.cpp:16: undefined reference to `array_pointer(int*, int)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Here is my CMakeLists.txt:这是我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)

aux_source_directory(src/main/cpp/cpp_basic/airthmatic CPP_SRC)
aux_source_directory(src/main/cpp/cpp_basic CPP_BASIC_SRC)

include_directories(src/main/cpp/cpp_basic/airthmatic)
include_directories(src/main/cpp/cpp_basic)

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        src/main/cpp/native-lib.cpp
        )

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)

add_library(mycpp-lib

            SHARED

        ${CPP_SRC}
        ${CPP_BASIC_SRC})


target_link_libraries( # Specifies the target library.
        native-lib


        ${mycpp-lib}

        ${log-lib}

        )

The mycpp-lib target name is not a variable defined with the set() command, so expanding it with ${mycpp-lib} yields an empty string. mycpp-lib目标名称不是使用set()命令定义的变量,因此使用${mycpp-lib}扩展它会产生一个空字符串。 When using target_link_libraries() , you can simply put the target name (without ${} ) when linking previously-defined targets:使用target_link_libraries()时,您可以在链接先前定义的目标时简单地输入目标名称(不带${} ):

target_link_libraries( # Specifies the target library.
        native-lib
        mycpp-lib
        ${log-lib}
        )

Note, for log-lib you do need the ${} to expand the cached variable defined by the find_library() call.请注意,对于log-lib ,您确实需要${}来扩展find_library()调用定义的缓存变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 clang++:错误:链接器命令失败,退出代码为 1 Qt Android - clang++: error: linker command failed with exit code 1 Qt Android NDK构建错误(错误:链接器命令失败,退出代码为1(使用-v查看调用)) - NDK build error (error: linker command failed with exit code 1 (use -v to see invocation)) android opencv 3.4.1 Build命令失败。 未定义的引用 - android opencv 3.4.1 Build command failed. Undefined reference to NDK-生成命令失败。 执行进程android时出错 - NDK- Build command failed. Error while executing process android Ionic Android Build Error:cmd:命令失败,退出代码为1 [解决方案] - Ionic Android Build Error: cmd: Command failed with exit code 1 [solution] 命令失败,退出代码为1错误输出:FAILURE:生成失败,出现异常 - Command failed with exit code 1 Error output: FAILURE: Build failed with an exception 使用 Android NDK 使用 clang++ 编译 C++ 代码时未定义对“_Unwind_Resume”的引用 - undefined reference to `_Unwind_Resume' when compiling C++ code with clang++ using Android NDK cordova build android 错误:系统找不到指定的路径。 错误:cmd:命令失败,退出代码为 1 - cordova build android error : The system cannot find the path specified. Error: cmd: Command failed with exit code 1 Cordova版本:命令失败,退出代码为8 - Cordova build: Command failed with exit code 8 在Android模拟器上运行Cordova错误:“android:命令失败,退出代码为2” - Cordova error running on android emulator: “android: Command failed with exit code 2”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM