使用 CMake C++17 项目设置 Travis CI
Setting up Travis CI with CMake C++17 project
我正在尝试使用C++17项目设置Travis CI。我们使用CLion进行开发,这意味着我们有一个自动生成的CMakeLists.txt文件。我是从命令行编译和运行C++的新手。
据我了解,特拉维斯使用的所有内容都已经过时,需要更新才能与 C++17 一起使用。到目前为止,我的 .travis.yml 看起来像这样,我相信它有很多问题。
dist: trusty
sudo: require
language: cpp
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-6
- g++-6
- cmake
script:
- sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
- sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++
- export CC=/usr/bin/gcc-6
- export CXX=/usr/bin/g++-6
- cmake --version
- cmake CMakeLists.txt
- cmake --build . --target neat
生成失败,因为无法导入 C++17 库之一。
编辑添加了特拉维斯错误消息。
$ git clone --depth=50 --branch=feature/travis-ci https://github.com/sheldonkwoodward/bNEAT.git sheldonkwoodward/bNEAT
Cloning into 'sheldonkwoodward/bNEAT'...
remote: Counting objects: 778, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 778 (delta 9), reused 13 (delta 5), pack-reused 759
Receiving objects: 100% (778/778), 2.62 MiB | 12.71 MiB/s, done.
Resolving deltas: 100% (470/470), done.
$ cd sheldonkwoodward/bNEAT
$ git checkout -qf e1827e4ca53b041322e92dc207f1e133968a69f8
$ export CXX=g++
$ export CC=gcc
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0.01s$ sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
The command "sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc" exited with 0.
0.01s$ sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++
The command "sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++" exited with 0.
0.00s$ export CC=/usr/bin/gcc-6
The command "export CC=/usr/bin/gcc-6" exited with 0.
0.00s$ export CXX=/usr/bin/g++-6
The command "export CXX=/usr/bin/g++-6" exited with 0.
0.13s$ cmake --version
cmake version 3.9.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
The command "cmake --version" exited with 0.
0.91s$ cmake CMakeLists.txt
-- The C compiler identification is GNU 6.4.0
-- The CXX compiler identification is GNU 6.4.0
-- Check for working C compiler: /usr/bin/gcc-6
-- Check for working C compiler: /usr/bin/gcc-6 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++-6
-- Check for working CXX compiler: /usr/bin/g++-6 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/travis/build/sheldonkwoodward/bNEAT
The command "cmake CMakeLists.txt" exited with 0.
0.15s$ cmake --build . --target neat
Scanning dependencies of target neat
[ 11%] Building CXX object CMakeFiles/neat.dir/main.cpp.o
/home/travis/build/sheldonkwoodward/bNEAT/src/SnakeGame.hpp:9:20: fatal error: optional: No such file or directory
#include <optional>
^
compilation terminated.
make[3]: *** [CMakeFiles/neat.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/neat.dir/all] Error 2
make[1]: *** [CMakeFiles/neat.dir/rule] Error 2
make: *** [neat] Error 2
The command "cmake --build . --target neat" exited with 2.
Done. Your build exited with 1.
CMakeList.txt
cmake_minimum_required(VERSION 3.8)
project(neat)
set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES main.cpp src/ANN.cpp src/ANN.hpp src/ConnectionGene.cpp src/ConnectionGene.hpp src/Gene.cpp src/Gene.h src/Node.cpp src/Node.hpp src/NEAT.cpp src/NEAT.hpp src/SnakeGame.cpp src/SnakeGame.hpp src/Snake.cpp src/Snake.hpp)
# Tests
enable_testing()
add_subdirectory(tests)
add_executable(neat ${SOURCE_FILES})
解决方案是使用 gcc-7 和 g++-7 来添加对 std::optional 的支持。我的工作.travis.yml:
language: cpp
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
script:
- export CC=gcc-7
- export CXX=g++-7
- cmake --version
- cmake CMakeLists.txt
- cmake --build . --target neat
相关文章:
- C++ MFC Libraries in Travis CI
- 仅在使用 gradle 在 Travis CI 上编译时才"multiple definition" googletest 符号
- 使用 CMake C++17 项目设置 Travis CI
- C++ Cmake没有在Travis CI服务器上设置编译器语言标准
- Travis-CI Complex Makefile fails
- Travis CI 中奇怪的编译器错误不会在本地计算机上发生
- Travis CI 找不到头文件
- 如何使用"trusty"映像在本地执行C++程序的Travis CI?
- QT QOverload没有在Travis CI上声明在这个范围内
- Travis-Ci 安装并运行 CxxTest
- Travis CI似乎是从错误的Stdlib读书
- 在 Travis CI 上运行 C++ 测试时出现问题.Cmake 配置.如何在特拉维斯 ci 上运行测试套件?
- Travis CI:Clang在应推导移动构造函数时推论复制构造函数
- Travis CI with Clang 3.4 and C++11
- g++ 5.4.0 的 asan 不适用于 travis CI
- 是否有C 中使用OpenCV和Travis CI的示例项目
- 使用Travis CI编译c++项目
- Travis CI with C++14 and Linux
- 使用cppunit与travis-ci.org进行c++集成
- Travis CI 不会在发布中编译,找不到库