代码之家  ›  专栏  ›  技术社区  ›  Canato Dogbert

在OpenCV上。C++编译器不能编译简单的测试程序。使用CLAN+++

  •  1
  • Canato Dogbert  · 技术社区  · 6 年前

    目标: 使用带有conan和opencv的交叉编译构建脚本为Android编译外部库。

    我今天的环境:

    • 操作系统: Macos High Sierra 10.13.6
    • 康南: 1.7.3 。/cell/conan/1.6.1/bin/conan
    • python: 2.7.10. /usr/bin/python (tryed with 3 too)]
    • <> LI> GC/C++:EM> 82.0 <代码> /opt/Posi/BIN/GCC-MMP-8}/opt/Studio/BI/G++-MP-8 (引用CLAN使用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

    <强>问题:< /强>开放CV不编译C++。主要信息是

    cxx编译器标识为clang 6.0.2 --C编译器标识为clang 6.0.2 --检查cxx编译器是否正常工作:/users/<user>/library/android/sdk/ndk bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --检查cxx编译器是否正常工作:/users/<user>/library/android/sdk/ndk bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++--损坏 cmake错误,位于/applications/cmake.app/contents/share/cmake-3.12/modules/cmakestcxcompiler.cmake:45(消息): C++编译器 “/users/<user>/library/android/sdk/ndk bundle/toolchains/llvm/prebuilt/darwin-x86_/bin/clang++” 无法编译简单的测试程序。 失败,输出如下: 更改目录:/users/<user>/.conan/data/opencv/3.4.1/ins/stable/build/4492059A128C69658616e0cf3d3f007e2ce6603c/cmakefiles/cmaketmp 运行build命令:“/users/<user>/library/android/sdk/cmake/3.6.4111459/bin/ninja”“cmtc_4338c” [1/2]生成cxx对象cmakefiles/cmtc c.dir/testcxxcompiler.cxx.o [2/2]链接cxx可执行文件cmtc c 失败:&&/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 ou-first-wl,-headerpad_max_install_names cmakefiles/cmtc_4338c.dir/testcxcompiler.cxx.o-o cmtc_4338c&: ld:找不到-lc的库++ clang++:错误:链接器命令失败,退出代码为1(使用-v查看调用) 忍者:生成已停止:子命令失败。 CMAKE将无法正确生成此项目。 < /代码>
    • cmaketmp是一个文件夹,空的。
    • cmakeerror在“…fail with the following output”之后具有相同的消息

    它正在请求 ld library。但在llvm文件夹上没有 llvm-ld ,如果我没有错的话,它是在4.0上删除的。我用的是10.0。这是我文件夹中的内容

    • obs :正如您所见,我不知道如何以正确的方式设置标志,也不知道这是否会改变某些东西。

    代码:

    构建脚本.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安装..%s“%(build_dir,conan_install_arguments)
    
    操作系统(conan_install_命令)
    < /代码> 
    
    

    安卓.cmake

    set(cmake制作程序/users/vcanato/library/android/sdk/cmake/3.6.4111459/bin/ninja)
    set(cmake_android_ndk/users/vcanato/library/android/sdk/ndk bundle/)
    < /代码> 
    
    

    我已经尝试过的内容

    生成脚本时

    compiler=clang
    编译器.version=5.0
    compiler.libcxx=libc++
    OS= Android
    OpAPI级别=21
    ARMV7
    < /代码> 
    
    

    obs:gcc在弃用中,所以没有它是个不错的解决方案,但仍然不起作用。

    compiler=gcc
    编译器.version=4.9
    compiler.libcxx=libstdc++
    OS= Android
    OpAPI级别=21
    ARMV7
    build_type=发布
    < /代码> 
    
    

    在android.cmake上:

    cmake_minimum_required(3.4版致命错误)
    包含目录(“/Ur/本地/地窖/Gcc/0.2.0/Ic/C++/0.2.0”)
    包含目录(“/rr/本地/地窖/gcc/0.2.0/包含/c++/2.02/x86y64-Apple -DelWun7.7.0/BIT”)
    SET(CMACHYCXXFLAG)${CMACHYCXXFLAG}}-I/Urr/Studio/Copy/C++/2.02.//)
    SET(CMACHYCXXFLAG)${CMACHYCXXFLAG}}-X/USR/ICO/C++/4.2.1//)
    设置(cmake_cxx_标准11)
    设置(需要Cxx_标准_)
    set(cmake_cxx_编译器/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”)。
    套件(Android_ABI ARM64-V8A)
    套装(cmake_android_api android-21)
    设置(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_编译器/usr/bin/g++“)
    < /代码> 
    
    

    前后project()

    工具链:

    /users/vcanato/library/android/sdk/ndk bundle/toolchains/arm-linux-androideabi-4.9
    /用户/vcanato/library/android/sdk/ndk bundle/toolchains/x86_-4.9
    < /代码> 
    
    

    我甚至尝试构建自己的standalone toolchain并使用conan cross building guide to android

    Stack和Github上的类似问题:

    操作系统:马科斯山脉10.13.6;
  • 柯南:1.7.3../Cellar/conan/1.6.1/bin/conan
  • 蟒蛇:2.7.10/usr/bin/python(也试了3次)
  • gcc/c++:2.2.0/opt/local/bin/gcc-mp-8 || /opt/local/bin/g++-mp-8(引用CLAN使用C++)
  • 铿锵/铿锵+:9 1.0/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin(这不是程序正在使用的程序)
  • CMake:3.2.2/Applications/CMake.app/Contents/bin/cmake
  • 使用NDK:十七
  • 问题:开放的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”之后具有相同的消息

    它要求半导体激光器库. 但在llvm文件夹上没有LLVM-LD,如果我没有错的话,它是4.0版的。我用的是10.0。这是我文件夹中的内容

    enter image description here

    • 光突发交换系统:正如你所看到的,我不知道如何以正确的方式设置标志,也不知道这是否会改变某些事情。

    代码:

    建筑脚本

    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)
    

    安德鲁

    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/)
    

    我已经试过了

    论建筑脚本

    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()

    Toolchains:

    /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使用Conan cross building guide to Android

    关于Stack和Github的类似问题:

    1 回复  |  直到 6 年前
        1
  •  1
  •   Tsyvarev    6 年前

    在工具链中指定cmake_make_命令的正确方法是设置 隐藏物 变量:

    set(CMAKE_MAKE_PROGRAM /Users/vcanato/Library/Android/sdk/cmake/3.6.4111459/bin/ninja
        CACHE FILEPATH "")
    

    这两者都是隐含的 by documentation (如果变量由生成器设置,则设置缓存版本),并在 this CMake mailing .

    更多解释

    空虚 消息中第一个字符串的

    Make command was: "" "cmTC_27ba1"
    

    应该是“的第一个信号 出了点问题 “。它应该是与cmake生成器对应的可执行文件(或指向可执行文件的绝对路径),而不是空字符串。在这种情况下,生成器的可执行文件是 ninja .

    通常,C以更具描述性的方式发出有关问题的信号:

    未设置cmake_make_程序