在 OpenCV 上。 C++ 编译器无法编译简单的测试程序。使用 Clang++
On OpenCV. C++ Compiler is not able to compile a simple test program. Using Clang++
目标: 使用 Conan 和 OpenCV 的交叉编译构建脚本为 Android 编译外部库。
我今天的环境:
- OS: MacOS High Sierra 10.13.6;
- 柯南:1.7.3
../Cellar/conan/1.6.1/bin/conan
- Python: 2.7.10
/usr/bin/python
(也试过 3)
- GCC/C++: 8.2.0
/opt/local/bin/gcc-mp-8 || /opt/local/bin/g++-mp-8
(引用是因为 clang 使用 c++)
- Clang/Clang++: 9.1.0
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
(这不是程序使用的那个)
- CMake: 3.12.2
/Applications/CMake.app/Contents/bin/cmake
- 使用的 NDK:17
问题: Open CV 不编译 C++。主要信息是
-- The CXX compiler identification is Clang 6.0.2
-- The C compiler identification is Clang 6.0.2
-- Check for working CXX compiler: /Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
-- Check for working CXX compiler: /Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -- broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.12/Modules/CMakeTestCXXCompiler.cmake:45 (message):
The C++ compiler
"/Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/<user>/.conan/data/OpenCV/3.4.1/ins/stable/build/4492059a128c69658616e0cf3d3f007e2ce6603c/CMakeFiles/CMakeTmp
Run Build Command:"/Users/<user>/Library/Android/sdk/cmake/3.6.4111459/bin/ninja" "cmTC_4338c"
[1/2] Building CXX object CMakeFiles/cmTC_4338c.dir/testCXXCompiler.cxx.o
[2/2] Linking CXX executable cmTC_4338c
FAILED: : && /Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --sysroot=/Users/<user>/Library/Android/sdk/ndk-bundle/sysroot -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_4338c.dir/testCXXCompiler.cxx.o -o cmTC_4338c && :
ld: library not found for -lc++
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
- CMakeTmp 是一个空文件夹。
- CMakeError 在“..fail with the following output”之后有相同的消息
正在请求 LD 库。但是在 LLVM 文件夹上没有 LLVM-LD,如果我没记错的话,它在 4.0 上被删除了。我正在使用 10.0.这是我文件夹中的内容
- Obs:如您所见,我不知道如何以正确的方式设置 Flag,也不知道这是否会有所改变。
代码:
Buildscript.py
build_dir = "build_Android_Debug"
conan_install_arguments = "-s compiler=clang -s compiler.version=6.0 -s compiler.libcxx=libc++ -s os=Android -s os.api_level=26 -s arch=armv8 -s build_type=Debug"
android_cmake_toolchain_path = current_dir_absolute_path + "/cmake-toolchains/Android.cmake"
conan_install_arguments += " --env CONAN_CMAKE_TOOLCHAIN_FILE=\"%s\"" % android_cmake_toolchain_path
conan_install_arguments += " --env CONAN_CMAKE_FIND_ROOT_PATH=/Users/<user>/Library/Android/sdk/ndk-bundle/sysroot"
conan_install_arguments += " --env PATH=[/Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin]"
conan_install_arguments += " --env AR=llvm-ar"
conan_install_arguments += " --env AS=llvm-as"
conan_install_arguments += " --env CC=clang"
conan_install_arguments += " --env CXX=clang++"
conan_install_command = "cd %s && conan install .. %s" % (build_dir, conan_install_arguments)
os.system(conan_install_command)
Android.cmake
set(CMAKE_MAKE_PROGRAM /Users/vcanato/Library/Android/sdk/cmake/3.6.4111459/bin/ninja)
set(CMAKE_ANDROID_NDK /Users/vcanato/Library/Android/sdk/ndk-bundle/)
我已经尝试过的
在 Buildscript 上
compiler=clang
compiler.version=5.0
compiler.libcxx=libc++
os=Android
os.api_level=21
arch=armv7
Obs:Gcc 已弃用,因此没有它会是一个很好的解决方案,但仍然没有用。
compiler=gcc
compiler.version=4.9
compiler.libcxx=libstdc++
os=Android
os.api_level=21
arch=armv7
build_type=Release
在 Android.cmake:
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
include_directories("/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0")
include_directories( "/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/x86_64-apple-darwin17.7.0/bits")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I /usr/local/include/c++/8.2.0/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -X /usr/include/c++/4.2.1/")
set(CMAKE_CXX_STANDARD 11)
set(CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_CXX_COMPILER "/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++")
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(ANDROID_ABI arm64-v8a)
set(CMAKE_ANDROID_API android-21)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_TOOLCHAIN_FILE /Users/<user>/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake)
set(CMAKE_ANDROID_NDK /Users/<user>/Library/Android/sdk/ndk-bundle/ CACHE FILEPATH "")
在 CmakeList.txt
set(CMAKE_CXX_COMPILER "/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
前后project()
工具链:
/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9
/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/x86_64-4.9
我什至尝试构建自己的 standalone toolchain and use Conan cross building guide to Android
Stack 和 GitHub 上的类似问题:
- CMake “clang++ is not able compile a simple test program”
- "The C++ compiler "/usr/bin/c++.exe" is not able to compile a simple test program"
在工具链中指定 CMAKE_MAKE_COMMAND 的正确方法是设置 CACHE 变量:
set(CMAKE_MAKE_PROGRAM /Users/vcanato/Library/Android/sdk/cmake/3.6.4111459/bin/ninja
CACHE FILEPATH "")
这意味着 by documentation (if the variable is set by a generator, CACHE version is set), and in this CMake mailing。
更多解释
消息中第一个字符串的空
Make command was: "" "cmTC_27ba1"
应该是“出了点问题”的第一个信号。它应该是与 CMake 生成器对应的可执行文件(或可执行文件的绝对路径),而不是空字符串。在你的情况下,生成器的可执行文件是 ninja
.
通常,CMake 会以更具描述性的方式发出有关问题的信号:
CMAKE_MAKE_PROGRAM is not set
目标: 使用 Conan 和 OpenCV 的交叉编译构建脚本为 Android 编译外部库。
我今天的环境:
- OS: MacOS High Sierra 10.13.6;
- 柯南:1.7.3
../Cellar/conan/1.6.1/bin/conan
- Python: 2.7.10
/usr/bin/python
(也试过 3) - GCC/C++: 8.2.0
/opt/local/bin/gcc-mp-8 || /opt/local/bin/g++-mp-8
(引用是因为 clang 使用 c++) - Clang/Clang++: 9.1.0
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
(这不是程序使用的那个) - CMake: 3.12.2
/Applications/CMake.app/Contents/bin/cmake
- 使用的 NDK:17
问题: Open CV 不编译 C++。主要信息是
-- The CXX compiler identification is Clang 6.0.2
-- The C compiler identification is Clang 6.0.2
-- Check for working CXX compiler: /Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++
-- Check for working CXX compiler: /Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ -- broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.12/Modules/CMakeTestCXXCompiler.cmake:45 (message):
The C++ compiler
"/Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/<user>/.conan/data/OpenCV/3.4.1/ins/stable/build/4492059a128c69658616e0cf3d3f007e2ce6603c/CMakeFiles/CMakeTmp
Run Build Command:"/Users/<user>/Library/Android/sdk/cmake/3.6.4111459/bin/ninja" "cmTC_4338c"
[1/2] Building CXX object CMakeFiles/cmTC_4338c.dir/testCXXCompiler.cxx.o
[2/2] Linking CXX executable cmTC_4338c
FAILED: : && /Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --sysroot=/Users/<user>/Library/Android/sdk/ndk-bundle/sysroot -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_4338c.dir/testCXXCompiler.cxx.o -o cmTC_4338c && :
ld: library not found for -lc++
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
- CMakeTmp 是一个空文件夹。
- CMakeError 在“..fail with the following output”之后有相同的消息
正在请求 LD 库。但是在 LLVM 文件夹上没有 LLVM-LD,如果我没记错的话,它在 4.0 上被删除了。我正在使用 10.0.这是我文件夹中的内容
- Obs:如您所见,我不知道如何以正确的方式设置 Flag,也不知道这是否会有所改变。
代码:
Buildscript.py
build_dir = "build_Android_Debug"
conan_install_arguments = "-s compiler=clang -s compiler.version=6.0 -s compiler.libcxx=libc++ -s os=Android -s os.api_level=26 -s arch=armv8 -s build_type=Debug"
android_cmake_toolchain_path = current_dir_absolute_path + "/cmake-toolchains/Android.cmake"
conan_install_arguments += " --env CONAN_CMAKE_TOOLCHAIN_FILE=\"%s\"" % android_cmake_toolchain_path
conan_install_arguments += " --env CONAN_CMAKE_FIND_ROOT_PATH=/Users/<user>/Library/Android/sdk/ndk-bundle/sysroot"
conan_install_arguments += " --env PATH=[/Users/<user>/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin]"
conan_install_arguments += " --env AR=llvm-ar"
conan_install_arguments += " --env AS=llvm-as"
conan_install_arguments += " --env CC=clang"
conan_install_arguments += " --env CXX=clang++"
conan_install_command = "cd %s && conan install .. %s" % (build_dir, conan_install_arguments)
os.system(conan_install_command)
Android.cmake
set(CMAKE_MAKE_PROGRAM /Users/vcanato/Library/Android/sdk/cmake/3.6.4111459/bin/ninja)
set(CMAKE_ANDROID_NDK /Users/vcanato/Library/Android/sdk/ndk-bundle/)
我已经尝试过的
在 Buildscript 上
compiler=clang
compiler.version=5.0
compiler.libcxx=libc++
os=Android
os.api_level=21
arch=armv7
Obs:Gcc 已弃用,因此没有它会是一个很好的解决方案,但仍然没有用。
compiler=gcc
compiler.version=4.9
compiler.libcxx=libstdc++
os=Android
os.api_level=21
arch=armv7
build_type=Release
在 Android.cmake:
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
include_directories("/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0")
include_directories( "/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/x86_64-apple-darwin17.7.0/bits")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I /usr/local/include/c++/8.2.0/")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -X /usr/include/c++/4.2.1/")
set(CMAKE_CXX_STANDARD 11)
set(CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_CXX_COMPILER "/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++")
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(ANDROID_ABI arm64-v8a)
set(CMAKE_ANDROID_API android-21)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_TOOLCHAIN_FILE /Users/<user>/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake)
set(CMAKE_ANDROID_NDK /Users/<user>/Library/Android/sdk/ndk-bundle/ CACHE FILEPATH "")
在 CmakeList.txt
set(CMAKE_CXX_COMPILER "/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
前后project()
工具链:
/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9
/Users/vcanato/Library/Android/sdk/ndk-bundle/toolchains/x86_64-4.9
我什至尝试构建自己的 standalone toolchain and use Conan cross building guide to Android
Stack 和 GitHub 上的类似问题:
- CMake “clang++ is not able compile a simple test program”
- "The C++ compiler "/usr/bin/c++.exe" is not able to compile a simple test program"
在工具链中指定 CMAKE_MAKE_COMMAND 的正确方法是设置 CACHE 变量:
set(CMAKE_MAKE_PROGRAM /Users/vcanato/Library/Android/sdk/cmake/3.6.4111459/bin/ninja
CACHE FILEPATH "")
这意味着 by documentation (if the variable is set by a generator, CACHE version is set), and in this CMake mailing。
更多解释
消息中第一个字符串的空
Make command was: "" "cmTC_27ba1"
应该是“出了点问题”的第一个信号。它应该是与 CMake 生成器对应的可执行文件(或可执行文件的绝对路径),而不是空字符串。在你的情况下,生成器的可执行文件是 ninja
.
通常,CMake 会以更具描述性的方式发出有关问题的信号:
CMAKE_MAKE_PROGRAM is not set