android studio按照文档构建c++编译工程报了cmakelist.txt相关的错误,请问那个大佬遇到过讲解一下[问题点数:30分]

li669007031 2016-12-30 03:36:41
编译报错如下:
Build command failed.
Error while executing 'D:\SDK\cmake\3.6.3155560\bin\cmake.exe' with arguments {-HD:\MyTest\MyCpp\app -BD:\MyTest\MyCpp\app\.externalNativeBuild\cmake\debug\armeabi-v7a -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi-v7a -DANDROID_NDK=D:\SDK\android-ndk-r12b -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\MyTest\MyCpp\app\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=D:\SDK\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=D:\SDK\cmake\3.6.3155560\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 -DCMAKE_C_FLAGS=-D_EXAMPLE_C_FLAG1 -D_EXAMPLE_C_FLAG2 -DCMAKE_CXX_FLAGS=-D__STDC_FORMAT_MACROS -DCMAKE_VERBOSE_MAKEFILE=TRUE}
-- Check for working C compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- Check for working CXX compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
See also "D:/MyTest/MyCpp/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".
CMake Error at CMakeLists.txt:12 (add_library):
The target name "test" is reserved or not valid for certain CMake features,
such as generator expressions, and may result in undefined behavior.
CMake Error at CMakeLists.txt:43 (target_link_libraries):
Cannot specify link libraries for target "test" which is not built by this
project.
Error:executing external native build for cmake D:\MyTest\MyCpp\app\CMakeLists.txt
Build command failed.
Error while executing 'D:\SDK\cmake\3.6.3155560\bin\cmake.exe' with arguments {-HD:\MyTest\MyCpp\app -BD:\MyTest\MyCpp\app\.externalNativeBuild\cmake\release\armeabi-v7a -GAndroid Gradle - Ninja -DANDROID_ABI=armeabi-v7a -DANDROID_NDK=D:\SDK\android-ndk-r12b -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\MyTest\MyCpp\app\build\intermediates\cmake\release\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=D:\SDK\cmake\3.6.3155560\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=D:\SDK\cmake\3.6.3155560\android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 -DCMAKE_C_FLAGS=-D_EXAMPLE_C_FLAG1 -D_EXAMPLE_C_FLAG2 -DCMAKE_CXX_FLAGS=-D__STDC_FORMAT_MACROS -DCMAKE_VERBOSE_MAKEFILE=TRUE}
-- Check for working C compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- Check for working CXX compiler: D:/SDK/android-ndk-r12b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
See also "D:/MyTest/MyCpp/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/CMakeOutput.log".
CMake Error at CMakeLists.txt:12 (add_library):
The target name "test" is reserved or not valid for certain CMake features,
such as generator expressions, and may result in undefined behavior.
CMake Error at CMakeLists.txt:43 (target_link_libraries):
Cannot specify link libraries for target "test" which is not built by this
project.
Error:executing external native build for cmake D:\MyTest\MyCpp\app\CMakeLists.txt
...全文
1385 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
刘_sir 2019-04-25
  • 打赏
  • 举报
回复
博主我现在也遇见这个问题请问怎么去解决 谢谢
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI})

# 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 them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
SerialPort

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).
src/main/jni/SerialPort.c )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries 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 this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
SerialPort

# Links the target library to the log library
# included in the NDK.
${log-lib} )
aidiaidiaidi 2017-10-31
  • 打赏
  • 举报
回复
厉害了 ,我刚好遇到这个问题
li669007031 2016-12-31
  • 打赏
  • 举报
回复
问题解决了,研究了一晚上其实是我的cmakelist.txt中so库的名称不符合规范,android自己建立的c++支持项目中库名是native-lib,
我直接写的库名是test,必须将库名写成test-lib,然后编译就可以了

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧