如何为cmake指定新的gcc路径 [英] how to specify new gcc path for cmake

查看:4539
本文介绍了如何为cmake指定新的gcc路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作系统是centos,它在路径 / usr / bin / gcc 中有一个默认的gcc。但它是老,我需要一个新版本的gcc。所以我在一个新路径 / usr / local / bin / gcc 中安装一个新版本。

My OS is centos which has a default gcc in path /usr/bin/gcc. But it is old, I need a new version of gcc. So I install a new version in a new path /usr/local/bin/gcc.

运行 cmake ,它仍然使用旧版本的gcc路径( / usr / bin / gcc )。如何指定gcc到新路径( / usr / local / bin / gcc )。

But when I run cmake, it still uses the old version gcc path(/usr/bin/gcc) . How can I specify the gcc to new path(/usr/local/bin/gcc).

尝试用 / usr / local / bin / gcc 覆盖 / usr / bin / gcc ,但它不工作。

I have tried to overwrite /usr/bin/gcc with /usr/local/bin/gcc, but it not work.

推荐答案

不要覆盖 CMAKE_C_COMPILER 之前调用cmake:

Do not overwrite CMAKE_C_COMPILER, but export CC (and CXX) before calling cmake:

export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++
cmake /path/to/your/project
make

导出只需要执行一次,第一次配置项目时,那些值将从cmake缓存中读取。

The export only needs to be done once, the first time you configure the project, then those values will be read from the cmake cache.

这篇关于如何为cmake指定新的gcc路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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