我的c++应用程序无法在travis-ci中成功通过

Cannot make a successful pass in travis-ci for my C++ app

本文关键字:成功 travis-ci c++ 应用程序 我的      更新时间:2023-10-16

我正在做这个项目,它在我的桌面使用g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4cmake version 2.8.12.2编译得很好。

我是一个新的旅行-ci的东西,我写了一个.travis.yml脚本如下

language: cpp
compiler:
  - g++
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - gcc-4.8
    - g++-4.8
    - libboost-all-dev
    - cmake
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8 -std=c++11 -I/usr/include/boost -DENABLE_REINFORCEMENT_LEARNING" CC="gcc-4.8"; fi
before_script:
  - mkdir build
  - cd build
  - cmake ..
script: make

我的项目有boost库依赖。
我的问题是travis-ci指示编译器错误在我的timer变量。

#include "stdafx.hpp"
#include <list>
#include <mutex>
#include <atomic>
#include <thread>
#include <fstream>
#include <sstream>
#include <signal.h>
#include <iostream>
#include <functional>
#include "timer.hpp"
#include "configs.hpp"
#include "incurses.hpp"
#include "quadrotor.hpp"
#include "main.helper.hpp"
#include "main.output.hpp"
#ifdef ENABLE_REINFORCEMENT_LEARNING
#   include "RLearner.Sarsa.hpp"
#endif
volatile bool
    sig_ctrl_c = false;
std::mutex log_lock;
> timer screener; <
// /home/travis/build/noise2/quadrotor-sim/main.cpp:27:1: error: ‘timer’ does not name a type
// timer screener;
scalar iter_simulation              = 0;
const size_t max_iter_simulation    = 1e+5;

您可以在这里看到travis-ci结果。

<标题> 30多个

1)当我在桌面上成功编译时,为什么这是一个错误?[我。E,我做错了什么?]
2)如何让我的项目通过考试?


编辑

请注意,timer类已经包含在内。

感谢@nfranklin我已经注意到什么是问题。为了解决这个问题,我不得不安装一个最新的boost版本,我想出了以下travis.yml脚本。

language: cpp
compiler:
  - g++
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    - boost-latest
    packages:
    - gcc-4.8
    - g++-4.8
    - libboost1.55-all-dev
    - cmake
install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8 -std=c++11 -DENABLE_REINFORCEMENT_LEARNING" CC="gcc-4.8"; fi
before_script:
  - mkdir build
  - cd build
  - cmake ..
script: make 

现在一切都好了

我认为问题在于您的travis-ci配置文件中的以下步骤:

install:
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8 -std=c++11 -I/usr/include/boost -DENABLE_REINFORCEMENT_LEARNING" CC="gcc-4.8"; fi

timer.hpp被包括在boost(即boost/timer.hpp)中,因为-I/usr/include/boost而不是你写的timer.hpp

您可以从该步骤中删除-I/usr/include/boost/usr/include是由gcc自动搜索头文件的,所以你所包含的boost头文件(例如#include)将会被找到。