如何为cmake指示gcc版本?

时间:2018-09-18 01:20:26

标签: c++ gcc cmake ubuntu-14.04

我在ubuntu gcc-4.8gcc-5中拥有GCC的多个版本。使用gcc -v将得到gcc version 4.8.4,因此看起来默认值为4.8,但我需要使用gcc-5

我尝试了How to specify new GCC path for CMake

export CC=/usr/bin/gcc-5
export CXX=/usr/bin/g++-5
// find the path by using 'which gcc-5'

和具体:

-DCMAKE_C_COMPILER=/usr/bin/gcc-5 
-DCMAKE_CXX_COMPILER=/usr/bin/g++-5

但给出错误:

ubuntu@skc:~/jumanpp-2.0.0-rc2/bld$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/Jumanpp -DCMAKE_C_COMPILER=/usr/bin/gcc-5 -DCMAKE_CXX_COMPILER=/usr/bin/g++-5
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/gcc-5
-- Check for working C compiler: /usr/bin/gcc-5 -- broken
CMake Error at /usr/share/cmake-3.2/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/usr/bin/gcc-5" is not able to compile a simple test
  program.

1 个答案:

答案 0 :(得分:0)

通过changing the default GCC解决了它:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6

(我需要更高的版本,所以从4.8更改为6)