Configuring travis to use the correct compiler is a bit complicated. Here's how to do it:
First of all, you need to configure the distribution to the correct one (the latest version of ubuntu supported by travis-ci) and require sudo.
dist: trusty sudo: require
Next, we install the language and compiler:
language: cpp compiler: gcc
So far so good. Now we can configure the apt install configuration:
addons: apt: sources: - ubuntu-toolchain-r-test packages: - gcc-6 - g++-6 - cmake
This adds ppa for the new version of our build tools and installs them. The next step is to configure links to the new gcc and g ++. /usr/local/bin searches up to /usr/bin , so our newly installed version 6 compilers will only be available with gcc and g++ . The beginning of your script: should look like this:
script: - sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc - sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++
Also add the following line if you want to check the versions of these tools:
- gcc -v && g++ -v && cmake
The versions returned from these commands are as follows:
gcc: 6.2.0 g++: 6.2.0 cmake: 3.2.2
This is basically it. The full .travis.yml is as follows:
dist: trusty sudo: required language: - cpp compiler: - gcc addons: apt: sources: - ubuntu-toolchain-r-test packages: - gcc-6 - g++-6 - cmake script: # Link gcc-6 and g++-6 to their standard commands - ln -s /usr/bin/gcc-6 /usr/local/bin/gcc - ln -s /usr/bin/g++-6 /usr/local/bin/g++ # Export CC and CXX to tell cmake which compiler to use - export CC=/usr/bin/gcc-6 - export CXX=/usr/bin/g++-6 # Check versions of gcc, g++ and cmake - gcc -v && g++ -v && cmake --version # Run your build commands next
source share