Mac交叉编译时NDK版本编译CMake错误
Created by: ysh329
- mac环境,交叉编译Android版本,默认
- 代码:dev分支,2019-03-06,aefc6333
- Cmake:3.13.4
android交叉编译的readme中说明需要NDKr17及以上,CMake3.0及以上。
在Mac环境交叉编译paddle-mobile android版本,使用不同NDK版本出现如下问题:
- 使用r17(含)以及以前的版本编译成功(但CMakeLists中存在v7变量没有用到的问题);
- 使用r18b,CMake报错:
/opt/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc, is not able to compile a simple test program.
; - 使用r19-beta2版本,CMake报错:
The CMAKE_C_COMPILER: /opt/android-ndk-r19-beta2/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc is not a full path to an existing compiler tool.
具体错误信息如下。
NDKr18
$ sh ./build.sh android
/opt/android-ndk-r18b
-- The C compiler identification is Clang 7.0.2
-- The CXX compiler identification is Clang 7.0.2
-- Check for working C compiler: /opt/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
/opt/android-ndk-r18b
-- Check for working C compiler: /opt/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc — broken
CMake Error at /usr/local/Cellar/cmake/3.13.4/share/cmake/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/opt/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/yuanshuai06/Baidu/code/paddle-mobile-repo/paddle-mobile/build/release/arm-v7a/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_6d58d/fast"
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_6d58d.dir/build.make CMakeFiles/cmTC_6d58d.dir/build
Building C object CMakeFiles/cmTC_6d58d.dir/testCCompiler.c.o
/opt/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/opt/android-ndk-r18b/sysroot -isystem /opt/android-ndk-r18b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=22 -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 -fPIE -o CMakeFiles/cmTC_6d58d.dir/testCCompiler.c.o -c /Users/yuanshuai06/Baidu/code/paddle-mobile-repo/paddle-mobile/build/release/arm-v7a/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_6d58d
/usr/local/Cellar/cmake/3.13.4/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6d58d.dir/link.txt —verbose=1
/opt/android-ndk-r18b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc --sysroot=/opt/android-ndk-r18b/sysroot -isystem /opt/android-ndk-r18b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=22 -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 -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot /opt/android-ndk-r18b/platforms/android-22/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L/opt/android-ndk-r18b/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -Wl,-z,nocopyreloc -pie -fPIE CMakeFiles/cmTC_6d58d.dir/testCCompiler.c.o -o cmTC_6d58d -latomic -lm
clang: warning: argument unused during compilation: '-Wa,--noexecstack' [-Wunused-command-line-argument]
ld: unknown option: --sysroot=/opt/android-ndk-r18b/platforms/android-22/arch-arm
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_6d58d] Error 1
make: *** [cmTC_6d58d/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:20 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/yuanshuai06/Baidu/code/paddle-mobile-repo/paddle-mobile/build/release/arm-v7a/CMakeFiles/CMakeOutput.log".
See also "/Users/yuanshuai06/Baidu/code/paddle-mobile-repo/paddle-mobile/build/release/arm-v7a/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found. Stop.
mkdir: ./build: No such file or directory
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file … target_directory
r19-beta2
sh ./build.sh android
/opt/android-ndk-r19-beta2
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:20 (project):
The CMAKE_C_COMPILER:
/opt/android-ndk-r19-beta2/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:20 (project):
The CMAKE_CXX_COMPILER:
/opt/android-ndk-r19-beta2/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/Users/yuanshuai06/Baidu/code/paddle-mobile-repo/paddle-mobile/build/release/arm-v7a/CMakeFiles/CMakeOutput.log".
See also "/Users/yuanshuai06/Baidu/code/paddle-mobile-repo/paddle-mobile/build/release/arm-v7a/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found. Stop.
mkdir: ./build: No such file or directory
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file … target_directory
更早期的NDK版本
尝试其它Mac NDK早期的版本,都正常,版本有:
android-ndk-r10e
android-ndk-r11c
android-ndk-r12b
android-ndk-r13b
android-ndk-r14b
android-ndk-r15c
android-ndk-r16b
android-ndk-r17b
android-ndk-r17c