据我所知,更改 cmake 使用的 objective-c ++ 编译器的最佳方法是在调用 cmake 之前更改 CXX
环境变量:
$ export CXX="clang++" && cmake --build
Travis CI 构建根据构建的设置设置 CXX
和 CC
。所以如果你的 .travis.yml
中有这个:
language: cpp
compiler:
- gcc
- clang
script:
- cmake --build
- ./bin/foo
cmake
第一次应该使用 GCC 而 Clang 不是吗?
相反,GCC 构建编译得很好(它是 cmake 使用的默认编译器),但 Clang 版本也使用 GCC:
0.01s$ echo $CC $CXX
clang clang++
The command "echo $CC $CXX" exited with 0.0.02s$ $CXX --version
clang version 3.4 (tags/RELEASE_34/final) Target: x86_64-unknown-linux-gnu Thread model: posixRunning: cmake -G "Unix Makefiles" -Wno-dev ../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
-- Detecting CXX compiler ABI info - done
我什至试图在调用之前再次设置这些变量:
- if [ "$CXX" == "clang++" ]; then export CXX="clang++" && cmake --build; fi
- if [ "$CXX" == "g++" ]; then export CXX="g++" && cmake --build; fi
我认为这没有多大意义...
Here是使用 GCC 成功构建,here (应该是)clang 构建。
我的问题是:如何更改 Travis CI 下 cmake 使用的编译器?
Here是我的 .travis.yml。
最佳答案
解释
在您的 .travis.yml
中我们看到:
- if [ "$CXX" == "clang++" ]; then export CXX="clang++" && bii cpp:build; fi
- if [ "$CXX" == "g++" ]; then export CXX="g++" && bii cpp:build; fi
biicode
的命令 bii cpp:build
使用 biicode
的默认生成器运行 CMake,即 “Unix Makefiles”
用于 UNIX 平台(GNU 工具链)。阅读:Biicode C++ documentation - Generators and IDEs .
此行为在您的日志中可见:运行:cmake -G "Unix Makefiles"-Wno-dev ../cmake
(https://travis-ci.org/Manu343726/Turbo/jobs/33889114,第 257 行)
CMake 并不总是寻找环境变量 CXX/CC
(如 CMake FAQ 中所述)。这取决于所选的发电机。当我在没有生成器的情况下调用 CMake 时,它对我有用(我的 travis 文件:https://github.com/quepas/Graph-ene/blob/master/.travis.yml)。
解决方案
- 单独使用 CMake 和方法 2 ( CMake FAQ - How do I use a different compiler? ) 中描述的
cmake -D
格式 - 设置
biicode
以使用正确的 CMake 生成器 ( Biicode C++ Configuration ) 或使用biicode
的自定义工具链 ( Biicode - Using custom toolchain )
关于c++ - 在 TravisCI 下为 cmake 更改 C++ 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25567391/