I have a .travis.yml file inside my repo (which will always run whenever I push to github) that looks like this:
---
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"
The yaml runs perfectly up until the make statement, where it logs the following message:
$ 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 .
Apparently, the build fails because the CMAKE_CXX_FLAGS have been set with a value of -Werror=strict-aliasing, inside the CMakeLists.txt file that is in the folder that contains the file json_value.cpp.o. Since the script always runs remotely, I cannot modify such value.
Is there any way I can make the "warnings being treated as errors" message go away? Anyone had a similar problem? Thank you.
PD: Link to full log here.
I finally found a solution:
The problem was that, even though the 4.9 versions of gcc and g++ compilers were installed, the container did not took these as the default. So, I had to force the build to take these compilers as default:
- cd build
- export CC=/usr/bin/gcc-4.9
- export CXX=/usr/bin/g++-4.9
- cmake ..
Since these are the compilers the CMakeFiles are supposed to run, the build passes smoothly.