【问题标题】:How do you set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER for building Assimp for iOS?你如何设置 CMAKE_C_COMPILER 和 CMAKE_CXX_COMPILER 来为 iOS 构建 Assimp?
【发布时间】:2012-07-21 01:51:41
【问题描述】:

当我尝试通过运行 build_ios.sh 来构建 Assimp 时,它告诉我:

CMake Error: your C compiler: "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc" was not found.   Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.

我需要的路径是:

/Applications/XCode.app/Contents/Developer/Platforms/...

我尝试在build_ios.sh 和IPHONE_xxxx_TOOLCHAIN.cmake 中更改DEVROOT,因为这似乎是生成CMAKE_C_COMPILER 等的原因,但它仍然给我同样的错误。

【问题讨论】:

  • 您找到解决方案了吗?

标签: ios cmake


【解决方案1】:

选项 1:

您可以像这样在命令行中设置 CMake 变量:

cmake -D CMAKE_C_COMPILER="/path/to/your/c/compiler/executable" -D CMAKE_CXX_COMPILER "/path/to/your/cpp/compiler/executable" /path/to/directory/containing/CMakeLists.txt

请参阅this 了解如何创建 CMake 缓存条目。


选项 2:

在您的 shell 脚本 build_ios.sh 中,您可以设置环境变量 CC 和 CXX 分别指向您的 C 和 C++ 编译器可执行文件,例如:

export CC=/path/to/your/c/compiler/executable
export CXX=/path/to/your/cpp/compiler/executable
cmake /path/to/directory/containing/CMakeLists.txt

选项 3:

编辑“Assimp”的CMakeLists.txt文件:在顶部添加这些行(必须在使用project()或enable_language()命令之前添加)

set(CMAKE_C_COMPILER "/path/to/your/c/compiler/executable")
set(CMAKE_CXX_COMPILER "/path/to/your/cpp/compiler/executable")

请参阅 this 以了解如何在 CMake 中使用 set 命令。此外,this 是了解一些常见 CMake 变量使用的有用资源。


以下是官方常见问题解答中的相关条目:https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler

【讨论】:

  • 我们可以使用选项 3 来使用编译器选项吗?我必须将其设置为arm-linux-gnueabli-gcc -mfloat-fpu=hard。这可能吗?它在执行时添加分号而不是空格
  • cmake命令在赋值cmake变量时遗漏了一个等号:应该是cmake -DCMAKE_C_COMPILER="/path/to/your/c/compiler/executable" -DCMAKE_CXX_COMPILER="/path/to/your/cpp/compiler/executable" /path/to/directory/containing/CMakeLists.txt
  • 在选项 #3 中,cmake 忽略了 project() 命令后的 2 个变量设置
  • 选项 2:根本不起作用,它被忽略了
【解决方案2】:

cc 和 cxx 位于 /Applications/Xcode.app 内。这应该找到正确的路径

export CXX=`xcrun -find c++`
export CC=`xcrun -find cc`

【讨论】:

    【解决方案3】:

    解决方案

    1. 有时项目是在安装g++ 之前创建的。所以先安装g++ 然后重新创建你的项目。这对我有用。
    2. 在 CMakeCache.txt 中粘贴以下行: CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

    注意g++ 的路径取决于操作系统。我使用了通过which g++获得的fedora路径

    【讨论】:

      猜你喜欢
      • 2018-10-28
      • 1970-01-01
      • 2011-10-05
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 2011-10-24
      相关资源
      最近更新 更多