如何让 CMake 在 Mac OS X 上使用 GCC 而不是 Clang? [英] How can I make CMake use GCC instead of Clang on Mac OS X?

查看:83
本文介绍了如何让 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 不(总是)听 CCCXX.而是使用 CMAKE_C_COMPILERCMAKE_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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆