构建命令失败。执行过程时出错
Posted
技术标签:
【中文标题】构建命令失败。执行过程时出错【英文标题】:Build command failed. Error while executing process 【发布时间】:2019-04-04 13:19:24 【问题描述】:我在我的代码中包含了 boost、cpprest 和 openssl,但它给了我错误,比如在 android studio 中使用 ndk 我给出了目录的所有路径并添加到程序中 它构建成功,但是当我运行它时,它给了我以下错误
Build command failed.
Error while executing process C:\Users\Dell\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments --build D:\Android studio project\CppAddLibrary\app\.externalNativeBuild\cmake\debug\armeabi-v7a --target native-lib
ninja: error: '/armeabi-v7a/libboost_system.so', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so', missing and no known rule to make it
我的 CMakeList.txt 是
cmake_minimum_required(VERSION 3.4.1)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp)
#---------------boost--------------------------
add_library (boost_system SHARED IMPORTED)
set_target_properties( boost_system PROPERTIES IMPORTED_LOCATION
$-DMY_BOOST_LIBS_DIR/$ANDROID_ABI/libboost_system.so
)
#--------------boost_crono---------------------------
add_library( boost_chrono SHARED IMPORTED)
set_target_properties(boost_chrono PROPERTIES IMPORTED_LOCATION
$DMY_BOOST_LIBS_DIR/$ANDROID_ABI/libboost_chrono.so
)
#----------openssl-------------------------------
add_library(ssl SHARED IMPORTED)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION
$DMY_OPENSSL_LIBS_DIR/$ANDROID_ABI/libssl.a
)
#--------------cpprest---------------------------
add_library( cpprestsdk SHARED IMPORTED)
set_target_properties(cpprestsdk PROPERTIES IMPORTED_LOCATION
$DMY_OPENSSL_LIBS_DIR/$ANDROID_ABI/libcpprest.a
)
#-----------------------------------------
include_directories( $DMY_BOOST_INC_DIR
)
include_directories( $DMY_OPENSSL_INC_DIR
)
include_directories( $DMY_CPPRESTSDK_INC_DIR
)
#-----------------------------------------
find_library (log-lib log)
#-----------------------------------------
target_link_libraries( # Specifies the target library.
native-lib
$log-lib
boost_system
boost_chrono
openssl
cpprestsdk
)
我的 build.graddle(App) 是
apply plugin: 'com.android.application'
def my_boost_dir = local_props("boost.dir")
def my_boost_dir_libs = my_boost_dir + "libs\\llvm"
def my_boost_dir_inc = my_boost_dir + "/include"
def my_openssl_dir = local_props("openssl.dir")
def my_openssl_dir_libs = my_openssl_dir + "/Prebuilt/armv7-shared/lib"
def my_openssl_dir_inc = my_openssl_dir + "/Prebuilt/armv7-shared/include/openssl"
def my_cpprestsdk_dir = local_props("cpprestsdk.dir")
def my_cpprestsdk_dir_libs = my_cpprestsdk_dir + "/armeabi-v7a/lib"
def my_cpprestsdk_dir_inc = my_cpprestsdk_dir + "/include"
机器人 compileSdkVersion 28 默认配置 applicationId "com.example.dell.cppaddlibrary" minSdkVersion 27 targetSdkVersion 28 版本代码 1 版本名称“1.0” testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 外部原生构建 制作 cppFlags "" 参数“-DANDROID_STL=c++_shared”
arguments '-DMY_BOOST_LIBS_DIR=' + my_boost_dir_libs
arguments '-DMY_BOOST_INC_DIR=' + my_boost_dir_inc
arguments '-DMY_OPENSSL_LIBS_DIR=' + my_openssl_dir_libs
arguments '-DMY_OPENSSL_INC_DIR=' + my_openssl_dir_inc
arguments '-DMY_OPENSSL_LIBS_DIR=' + my_cpprestsdk_dir_libs
arguments '-DMY_OPENSSL_INC_DIR=' + my_cpprestsdk_dir_inc
ndk
abiFilters 'armeabi-v7a', 'x86', 'x86_64', 'arm64-v8a'
stl 'c++_shared'
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild
cmake
path "CMakeLists.txt"
sourceSets
main
jniLibs.srcDirs = [
my_boost_dir_libs,
my_openssl_dir_libs,
my_cpprestsdk_dir_libs
]
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
def local_props(key) // reads ~ value from local.properties file
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def val = properties.getProperty(key, null)
if (val == null)
throw new GradleException("""\
cant find value '$key' in file 'local.properties'. """)
return val
Local.Properties 是
ndk.dir=C\:\\Users\\Dell\\AppData\\Local\\Android\\Sdk\\ndk-bundle
boost.dir=C\:\\Users\\Dell\\AppData\\Local\\Android\\Sdk\\ndk-bundle\\boost
openssl.dir=D\:\\Android studio project\\CppAddLibrary\\app\\Prebuilt_OpenSSL
cpprestsdk.dir=D\:\\Android studio project\\CppAddLibrary\\app\\cpprestsdk
sdk.dir=C\:\\Users\\Dell\\AppData\\Local\\Android\\Sdk
请帮我解决这个问题
提前致谢
现在它向我显示错误
Build command failed.
Error while executing process C:\Users\Dell\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments --build D:\Android studio project\CppAddLibrary\app\.externalNativeBuild\cmake\debug\armeabi-v7a --target native-lib
[1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\Dell\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi27 --gcc-toolchain=C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -DBOOST_SYSTEM_NO_DEPRECATED -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-27/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -LC:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/boost/libs/llvm/armeabi-v7a/libboost_system.so C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/boost/libs/llvm/armeabi-v7a/libboost_chrono.so -lopenssl ../../../../cpprestsdk/lib/armeabi-v7a/libcpprest.a -latomic -lm "C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so" && cd ."
C:/Users/Dell/AppData/Local/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lopenssl`enter code here`
【问题讨论】:
【参考方案1】:set_target_properties( boost_system PROPERTIES IMPORTED_LOCATION
$-DMY_BOOST_LIBS_DIR/$ANDROID_ABI/libboost_system.so
)
$-DMY_BOOST_LIBS_DIR
应该是什么?该变量的评估结果为零,这就是您走错路的原因。
【讨论】:
从中删除-D
?
谢谢它对我有用,但还有另一个问题,它显示链接错误。如何链接我的库以在我的程序中使用?
阅读错误信息。 “找不到-lopenssl`在此处输入代码”您在某处有一个杂散的“`在此处输入代码”。
经过大量研究后我无法找到结果,请帮忙【参考方案2】:
我也遇到了同样的错误,我通过提供如下完整路径解决了这个问题:
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION /Users/rajiv/MicrTextReader/app/src/main/jniLibs/$ANDROID_ABI/libopencv_java3.so)
我使用的是 Mac,所以 Path 是 Mac 格式。您可以根据您的 PC 更改路径。
【讨论】:
以上是关于构建命令失败。执行过程时出错的主要内容,如果未能解决你的问题,请参考以下文章
签署 android 捆绑包时出错:任务“:app:signReleaseBundle”执行失败
执行命令时代码构建失败并出现错误:npm install。原因:退出状态 127