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

查看:622
本文介绍了如何在Mac OS X上使CMake使用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).

我已经安装了gcc-4.8使用brew,设置所有依赖项,标头等,现在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 一个nd 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.

这篇关于如何在Mac OS X上使CMake使用GCC而不是Clang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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