Travis CI with Clang 3.4 and C++11

wilx picture wilx · Mar 1, 2014 · Viewed 12k times · Source

Is it possible to get Travis CI working with Clang that is capable of C++11? (I want Clang, not GCC, I already have GCC 4.8 working in Travis CI.) It appears that the version that is there pre-installed is not C++11 capable. All my attempts at installing any newer version end up failing because of this:

In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:57:   
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:269:39: error:
use of undeclared identifier '__float128'
struct __is_floating_point_helper<__float128>

I have seen the -D__STRICT_ANSI__ trick but that clashes with other things for me.

Is it possible to get it working? See also my .travis.yml.

Answer

cdunn2001 picture cdunn2001 · Jun 18, 2015

There is now a better way to do this.

sudo: false
dist: trusty
language: cpp
os:
  - linux
compiler:
  - gcc
  - clang
install:
# /usr/bin/gcc is 4.6 always, but gcc-X.Y is available.
- if [[ $CXX = g++ ]]; then export CXX="g++-4.9" CC="gcc-4.9"; fi
# /usr/bin/clang has a conflict with gcc, so use clang-X.Y.
- if [[ $CXX = clang++ ]]; then export CXX="clang++-3.5" CC="clang-3.5"; fi
addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    - llvm-toolchain-precise-3.5 # not sure why we needed this
  packages:
    - gcc-4.9
    - g++-4.9
    - clang-3.5

(The explicit sudo: false will let it build in Docker (for speed) even if you have a pre-docker repo, according to Travis support.)

Thanks to solarce at Travis support for noticing my error and fixing the docs.