Search code examples
c++clangc++14travis-ci

Travis CI seems to be reading from the wrong stdlib


I'm just getting started with using travis-CI, so I apologize if this is a silly or obvious question.

Following the instructions here:

I wrote the following travis.yml

language: cpp

dist: trusty

matrix:
  include:
    - os: linux
      compiler: gcc
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-7
      env:
        - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
    - os: linux
      compiler: clang
      addons:
        apt:
          sources:
            - llvm-toolchain-trusty-5.0
          packages:
            - clang-5.0
      env:
        - MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"

before_install:
    - eval "${MATRIX_EVAL}"

script:
    - mkdir build
    - cd build
    - cmake -DCMAKE_VERBOSE_MAKEFILE=ON ..
    - cmake --build .
    - ctest

Which causes the following error in the clang build:

/home/travis/build/path_to_project/./include/abulafia/support/type_traits.h:20:12: error: no member named 'decay_t' in namespace 'std'; did you mean 'decay'?

/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:1725:11: note: 'decay' declared here

When compiling with the following command:

cd /home/travis/build/path_to_project/build/tests/char_set && /usr/bin/clang++-5.0 -Wall -pedantic -Wextra -std=c++17 -I/home/travis/build/path_to_project/./include -I/home/travis/build/path_to_project/googletest/googletest/include -o CMakeFiles/char_set_tests.dir/test_any.cpp.o -c

Which tells me it's loading gcc's libraries. Is there something I'm not understanding right here?

Thanks!


Solution

  • This can be fixed by installing g++7 alongside clang, to upgrade the standard library. The relevant matrix entry becomes:

    matrix:
      include:
        - os: linux
          addons:
            apt:
              sources:
                - llvm-toolchain-trusty-5.0
                - ubuntu-toolchain-r-test
              packages:
                - clang-5.0
                - g++-7
          env: MATRIX_EVAL="CC=clang-5.0 && CXX=clang++-5.0"
    

    Replacing this into the OP's yaml should do the trick. Note: compiler: clang was in excess – its effects get overridden by the eval "${MATRIX_EVAL}" trick.