Why does Cmake Always Choose GCC?

拥有回忆 提交于 2019-12-11 09:36:44

问题


For reasons that I cannot completely understand, Cmake awlays chooses the GNU compiler toolset when compiling software.

My enviroment looks like this:

which cc
/opt/cray/xt-asyncpe/4.9/bin/cc
which CC
/opt/cray/xt-asyncpe/4.9/bin/CC
echo $CC
/opt/cray/xt-asyncpe/4.9/bin/cc
echo $CXX
/opt/cray/xt-asyncpe/4.9/bin/CC

but when I use cmake I get this

Using existing /opt/cmake/2.8.4/bin/cmake
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info

And it builds all the software with g++ commands. Why is this going on? How does one set the compiler?


回答1:


I'm not sure why CMake favours GCC.

However, to set the compilers, use:

cmake <path to CMakeLists.txt> -DCMAKE_C_COMPILER=/opt/cray/xt-asyncpe/4.9/bin/cc -DCMAKE_CXX_COMPILER=/opt/cray/xt-asyncpe/4.9/bin/CC

These values will be cached, so subsequent runs of CMake (if required) can simply be invoked by:

cmake .



回答2:


You can also set the env vars CC and CXX much like autotools.

CC=cc CXX=CC cmake ...

Make sure you start with an empty build tree.



来源:https://stackoverflow.com/questions/10856952/why-does-cmake-always-choose-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!