Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building with more than one version of a compiler

How can I configure travis-ci such that my project builds with more than one version of a compiler?

Say, I want to build it with gcc-4.8, gcc-4.9, clang-3.4, clang-3.5 and clang-3.6.

I know how to build on both gcc and clang, but not on more than one version of them.

To give a little bit more context, my project is a C++ library and I want to ensure compatibility with those compilers.

like image 226
bst Avatar asked Mar 27 '15 23:03

bst


People also ask

What is GCC and make?

GNU Compiler Collection (GCC): a compiler suite that supports many languages, such as C/C++ and Objective-C/C++. GNU Make: an automation tool for compiling and building applications. GNU Binutils: a suite of binary utility tools, including linker and assembler.

What is the GCC version?

GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and the Linux kernel. With roughly 15 million lines of code in 2019, GCC is one of the biggest free programs in existence.

What is difference between G ++ and GCC?

DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.


1 Answers

It was (and still is) quite painful to figure out what is possible/allowed with Travis CI and what isn't. My current solution looks like this:

language: cpp
matrix:
  include:
    - os: linux
      compiler: gcc
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-4.8']
      env: COMPILER=g++-4.8

    - os: linux
      compiler: gcc
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-4.9']
      env: COMPILER=g++-4.9

    - os: linux
      compiler: gcc
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test']
          packages: ['g++-5']
      env: COMPILER=g++-5

    - os: linux
      compiler: clang
      env: COMPILER=clang++

    - os: linux
      compiler: clang
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5']
          packages: ['clang-3.5']
      env: COMPILER=clang++-3.5

    - os: linux
      compiler: clang
      addons:
        apt:
          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
          packages: ['clang-3.6']
      env: COMPILER=clang++-3.6

# Activate when 3.7 is released and the repository is available
#    - os: linux
#      compiler: clang
#      addons:
#        apt:
#          sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
#          packages: ['clang-3.7']
#      env: COMPILER=clang++-3.7

# Activate when we are allowed to use MacOS X
#    - os: osx
#      compiler: clang
#      env: COMPILER=clang++

script:
  make CXX=$COMPILER -j3

Some remarks:

  • The above uses the container-based infrastructure
  • Only one compiler is installed per container - speeds up the build and avoids problems as you often can not install several packages/compilers in parallel
  • You can not set CXX directly as Travis CI will overwrite it. You need an intermediate variable like COMPILER
  • The clang++ without extension is currently Clang 3.4
  • Clang 3.7 is not yet available, but should be shortly
  • Clang 3.8 (the development version) from the llvm-toolchain-precise repository is currently black-listed

(Note that the above will change/improve over time, now (2016-01-11) Clang 3.7 is available, as is MacOS X. The above is meant as a starting point, adapt as needed)

like image 68
Daniel Frey Avatar answered Sep 28 '22 18:09

Daniel Frey