How can I make CMake use GCC instead of Clang on Mac OS X?(如何让 CMake 在 Mac OS X 上使用 GCC 而不是 Clang?)
问题描述
我找不到有关它的任何信息,只能找到相反的信息(例如,如何将 CMake 设置为使用 clang).
I can't find any info on it, but only the other way around (e.g., how to set CMake to use clang).
我已经使用 brew 安装了 gcc-4.8,设置了所有依赖项、头文件等,现在 CMake 拒绝使用 gcc.
I've installed gcc-4.8 using brew, setup all dependencies, headers, etc, and now CMake refuses to use gcc.
我已经使用别名和实际条目设置了我的 bash 配置文件:
I've set my bash profile with both aliases and actual entries:
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
alias gcc='gcc-4.8'
alias cc='gcc-4.8'
alias g++='g++-4.8'
alias c++='c++-4.8'
然而,CMake 顽固地拒绝使用 gcc,而是恢复为 clang:
Yet CMake stubbornly refuses to use gcc and instead reverts back to clang:
air:build alex$ cmake -DCMAKE_BUILD_TYPE=DEBUG ..
-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
推荐答案
CMake 不(总是)听 CC 和 CXX.而是使用 CMAKE_C_COMPILER 和 CMAKE_CXX_COMPILER:
CMake doesn't (always) listen to CC and CXX. Instead use CMAKE_C_COMPILER and CMAKE_CXX_COMPILER:
cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ ...
另见文档.
或者,您可以提供一个工具链文件,但在这种情况下这可能有点矫枉过正.
Alternatively, you can provide a toolchain file, but that might be overkill in this case.
这篇关于如何让 CMake 在 Mac OS X 上使用 GCC 而不是 Clang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 CMake 在 Mac OS X 上使用 GCC 而不是 Clang?
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- c++ STL设置差异 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
