Jsoncpp cmake 在 TravisCI 中执行 github 时抛出被视为错误的警告
Jsoncpp cmake throws warning treated as error when executed inside TravisCI for github
我的存储库中有一个 .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。由于脚本总是 运行s 远程,我不能修改这样的值。
有什么方法可以让 "warnings being treated as errors" 消息消失吗?有人遇到过类似的问题吗?谢谢。
PD:Link 完整日志 here。
我终于找到了解决办法:
问题在于,即使安装了 4.9 版本的 gcc 和 g++ 编译器,容器也没有将它们作为默认值。
所以,我不得不强制构建将这些编译器作为默认值:
- cd build
- export CC=/usr/bin/gcc-4.9
- export CXX=/usr/bin/g++-4.9
- cmake ..
由于这些是 CMakeFiles 应该 运行 的编译器,构建顺利通过。
我的存储库中有一个 .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。由于脚本总是 运行s 远程,我不能修改这样的值。
有什么方法可以让 "warnings being treated as errors" 消息消失吗?有人遇到过类似的问题吗?谢谢。
PD:Link 完整日志 here。
我终于找到了解决办法:
问题在于,即使安装了 4.9 版本的 gcc 和 g++ 编译器,容器也没有将它们作为默认值。 所以,我不得不强制构建将这些编译器作为默认值:
- cd build
- export CC=/usr/bin/gcc-4.9
- export CXX=/usr/bin/g++-4.9
- cmake ..
由于这些是 CMakeFiles 应该 运行 的编译器,构建顺利通过。