我的repo中有一个.travis.yml文件(每次推送到github时都会运行),如下所示:
---
language: java
sudo: true
jdk: oraclejdk8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.5
- george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
packages:
- cmake
- cmake-data
- gcc-4.9
- g++-4.9
- clang-3.5
- valgrind
before_install:
- sudo apt-get -qq update
- git clone https://github.com/open-source-parsers/jsoncpp.git
- cd jsoncpp
- python amalgamate.py
- mkdir build
- cd build
- cmake ..
- make
script:
- cd ../..
- mvn install -Dlog4j.configurationFile="src/test/resources/log4j.xml"
yaml完美运行直到make语句,它会记录以下消息:
$ make
Scanning dependencies of target jsoncpp_lib_static
[ 16%] Building CXX object src/lib_json/CMakeFiles/jsoncpp_lib_static.dir/json_reader.cpp.o
[ 33%] Building CXX object src/lib_json/CMakeFiles/jsoncpp_lib_static.dir/json_value.cpp.o
/home/travis/build/fire-d/testDemo/jsoncpp/src/lib_json/json_value.cpp: In copy constructor ‘Json::Value::CZString::CZString(const Json::Value::CZString&)’:
/home/travis/build/fire-d/testDemo/jsoncpp/src/lib_json/json_value.cpp:273:78: error: conversion to ‘unsigned char:2’ from ‘unsigned int’ may alter its value [-Werror=conversion]
cc1plus: some warnings being treated as errors
make[2]: *** [src/lib_json/CMakeFiles/jsoncpp_lib_static.dir/json_value.cpp.o] Error 1
make[1]: *** [src/lib_json/CMakeFiles/jsoncpp_lib_static.dir/all] Error 2
make: *** [all] Error 2
The command "make" failed and exited with 2 during .
显然,构建失败是因为CMAKE_CXX_FLAGS已在包含文件json_value.cpp.o的文件夹中的CMakeLists.txt文件中设置了值-Werror = strict-aliasing。由于脚本总是远程运行,我无法修改这样的值。
有什么办法可以让“警告被视为错误”消息消失吗?有人有类似的问题吗?谢谢。
PD:链接到完整日志here。
答案 0 :(得分:0)
我终于找到了解决方案:
问题是,即使安装了4.9版本的gcc和g ++编译器,容器也没有将这些作为默认值。 因此,我必须强制构建将这些编译器作为默认值:
- cd build
- export CC=/usr/bin/gcc-4.9
- export CXX=/usr/bin/g++-4.9
- cmake ..
由于这些是CMakeFiles应该运行的编译器,因此构建顺利通过。