【问题标题】:Why does Cmake Always Choose GCC?为什么 Cmake 总是选择 GCC?
【发布时间】:2012-06-01 20:30:26
【问题描述】:

由于我无法完全理解的原因,Cmake awlays 在编译软件时选择了 GNU 编译器工具集。

我的环境是这样的:

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

但是当我使用 cmake 时,我得到了这个

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

它使用 g++ 命令构建所有软件。为什么会这样?如何设置编译器?

【问题讨论】:

    标签: cmake environment-variables cray


    【解决方案1】:

    您也可以像 autotools 一样设置环境变量 CC 和 CXX。

    CC=cc CXX=CC cmake ...

    确保从空的构建树开始。

    【讨论】:

    • +1 更容易...还要注意 make CC=cc CXX=cc 不适用于 cmake,它必须加前缀。
    【解决方案2】:

    我不确定为什么 CMake 偏爱 GCC。

    但是,要设置编译器,请使用:

    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
    

    这些值将被缓存,因此 CMake 的后续运行(如果需要)可以通过以下方式简单地调用:

    cmake .
    

    【讨论】:

    • 真正搞砸的是这个程序上的 ./configuration 调用了 cmake...这是我们生活的一个疯狂的世界。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2021-09-25
    • 2011-02-14
    • 1970-01-01
    • 2019-09-17
    • 1970-01-01
    相关资源
    最近更新 更多