Travis CI seems to be reading from the wrong stdlib - c++

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!

Yes, this is a well-known issue with the travis-ci build environment. It is compiling and linking against the default ubuntu-trusty libstdc++, which is the gcc 4-series stdlib and not even C++11 conforming.
See an issue I opened a long time ago.
If you need a C++14 libstdc++ with travis-ci, you should use docker and make a more recent ubuntu image. That's the best workaround AFAIK.

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.

Related

Boost libraries in MacOS "clang: error: unsupported option '-fopenmp'" [duplicate]

I am currently trying to deploy a project using openmp. I have the flag '-fopenmp' on Travis.
How could I fix that ?
In local I just brew install libopenmp which solved the issue. But not on Travis, what are the options ?
Using cython I got the following ".travis.yml"
os: linux
dist: xenial
language: python
python:
- "3.7"
cache: pip
addons:
apt:
packages:
- patchelf
matrix:
include:
- os: osx
# No version of Python is available via virtualenv on OS X workers, see https://github.com/travis-ci/travis-ci/issues/2312
language: generic
env: TOXENV=py37
fast_finish: true
before_install:
brew install libomp
install:
- pip install --upgrade "pip < 19.1" -r CI/requirements.txt
- python setup.py develop
script:
- pytest
Travis fails while executing :
clang -fno-strict-aliasing -fno-common -dynamic -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/openssl#1.1/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python#2/2.7.17/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c cpt/alphabet.c -o build/temp.macosx-10.13-x86_64-2.7/cpt/alphabet.o -fopenmp
While in local it compiles with python 3.7, how could I fix that aswell ?
On apple's llvm, -fopenmp is not supported. One should use brew's llvm.
The following ables to link openmp:
- brew install llvm libomp
- export CPP=/usr/local/opt/llvm/bin/clang;
For reference, the issue where there are all the commands: https://github.com/bluesheeptoken/CPT/issues/68#issuecomment-563342866

How to use clang-10 or gcc-10 when building via Github Actions?

I'm writing a library in C++ that implements a few different coroutine primitives, and the library is targeted at the newly released C++20. As a result, it also makes use of things like concepts that were added to the language in C++20.
I want to use github actions to build the library, but builds are failing because ubuntu-latest uses GCC 9 and CLang 9, but my library requires at least GCC 10 or Clang 10 to build.
I attempted to configure the build action by setting -DCMAKE_CXX_COMPILER=g++-10, but the action fails in the Configure CMake phase because g++-10 can't be found on the system.
Is there any way specify github actions should use GCC 10 or Clang 10?
This is the most recent workflow file I tried running:
name: CMake
on: [push]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE
And this is the point where it fails:
Run cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
The CMAKE_CXX_COMPILER:
g++-10
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/runner/work/conduit/build/CMakeFiles/CMakeOutput.log".
See also "/home/runner/work/conduit/build/CMakeFiles/CMakeError.log".
##[error]Process completed with exit code 1.
As Some programmer dude mentioned, installing g++ from apt is the way to go (unless it's installed by default); adds a minute or two to the build. Then you can tell cmake which compiler it should use by passing CC and CXX variables during configure step:
- run: |
sudo apt update
sudo apt install gcc-10 g++-10
shell: bash
# ... #
- run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
shell: bash
env:
CC: gcc-10
CXX: g++-10
Same solution applies when you want to use clang.
I am using both gcc-9 and clang-10 for C (only) project.
- name: Setup dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
sudo apt-get install -y gcc-9 llvm-10 clang-10
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-9 100 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-9
sudo update-alternatives \
--install /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-10 100 \
--slave /usr/bin/llvm-ranlib llvm-ranlib /usr/bin/llvm-ranlib-10 \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-10
sudo update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-10 100
PS you need to update more alternatives for C++ project, just example.
You can see what's installed by visiting https://github.com/actions/virtual-environments.
If you're trying this in 2022, now ubuntu-latest has "GNU C++ 9.3.0, 10.3.0". g++ is linked to version 9, but g++-10 is available on the PATH without any extra installation steps.

Specifying compiler versions in travis for cmake builds

The travis Building a C++ Project documentation shows how to specify gcc and clang compiler versions in build matrices. However, it does not show how to build projects with those compilers using cmake.
I amended the .travis.yml file here to specify gcc 9 and clang 8 as per the travis documentation, i.e.:
matrix:
include:
- compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-9
env:
- MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
- compiler: clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-bionic-8
packages:
- clang-8
- libstdc++-8-dev
env:
- MATRIX_EVAL="CC=clang-8 && CXX=clang++-8"
before_install:
- eval "${MATRIX_EVAL}"
- pip install --user cpp-coveralls
...
script:
- mkdir _builds
- cd _builds
- cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} ..
- make
- ./via-httplib_test
But is caused build errors when running cmake, e.g.:
$ cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} ..
CMake Error at /usr/local/cmake-3.12.4/share/cmake-3.12/Modules/CMakeDetermineCCompiler.cmake:48 (message):
Could not find compiler set in environment variable CC:
gcc-9.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/home/travis/build/kenba/via-httplib/_builds/CMakeFiles/CMakeOutput.log".
The command "cmake -DVIA_HTTPLIB_UNIT_TESTS=ON -DVIA_HTTPLIB_COVERAGE=ON ${CMAKE_OPTIONS} .." exited with 1.
I tried fixing the errors by specifying CMAKE_C_COMPILER and CMAKE_CXX_COMPILER for cmake, but I could not get it to work.
However, it builds correctly with:
env:
- MATRIX_EVAL="CC=gcc && CXX=g++"
...
env:
- MATRIX_EVAL="CC=clang && CXX=clang++"
but builds with the default bionic gcc and clang compilers, i.e.: GCC 7.4.0 and Clang 7, not GCC 9 and Clang 8.
How to write a .travis.yml file so that cmake can find and use
the compiler versions specified in a matrix?
Perhaps it was a Travis issue? Simply adding the g++-9 package and changing the variable to MATRIX_EVAL="CC=gcc-9 && CXX=g++-9" results in a successful compilation of your project with GCC 9.3.0
This is a minimal example that I use for building my project:
language: cpp
matrix:
include:
- os: linux
addons:
apt:
sources:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- clang-8
env:
- MATRIX_EVAL="CC=clang-8 CXX=clang++-8"
- os: linux
addons:
apt:
sources:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- g++-9
env:
- MATRIX_EVAL="CC=gcc-9 CXX=g++-9"
before_install:
- eval "${MATRIX_EVAL}"
script:
- cmake .
- make

Travis CI C++ Build succeed but travis exited with 1 and doesn't passes the test

I am trying to integrate my project with Travis CI, and when i build it everything seems to be ok, but the built is still failing and I get the message
Done. Your build exited with 1. but the CMake build give me message The command "cmake --build . -- -j2" exited with 0.
Here is my outupt of the build in travis-ci :
https://travis-ci.org/stelro/Fission-Engine
Here is the CMakeList.txt of the project:
https://github.com/stelro/Fission-Engine/blob/EntityComponentSystem/CMakeLists.txt
And here is the travis.yml:
https://github.com/stelro/Fission-Engine/blob/EntityComponentSystem/.travis.yml
Can someone help me and explaine me why I cannot pass the travis-ci build?
You are trying to install gcc-6 and set up links manually. Operations such as
ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
require sudo which is disabled in your .travis.yml file. The better approach would be to specify gcc-6 as part of your build matrix:
matrix:
include:
# g++ builds
- os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
env:
- COMPILER="g++-6"

Travis fails first build in matrix

I have started building my project on travis and, after managing to build with one compiler, I decided to cover more and use matrix builds to build with a variety of compilers on Linux. I have managed to get a configuration that builds successfully for all entries except the first one. The exact error I get is:
$ sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install g++-5 libncurses5-dev
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package g++-5
E: Couldn't find any package by regex 'g++-5'
apt-get.diagnostics
apt-get install failed
My travis configuration looks like:
sudo: false
language: generic
matrix:
include:
- os: linux
env: COMPILER_NAME=g++ CXX=g++-5 CC=gcc-5
addons:
apt:
source: &sources
- llvm-toolchain-precise-3.8
- llvm-toolchain-precise-3.7
- llvm-toolchain-precise-3.6
- ubuntu-toolchain-r-test
packages:
- g++-5
- libncurses5-dev
- os: linux
env: COMPILER_NAME=clang++ CXX=clang++-3.8 CC=clang-3.8
addons:
apt:
sources: *sources
packages:
- clang-3.8
- libncurses5-dev
- os: linux
env: COMPILER_NAME=clang CXX=clang++-3.7 CC=clang-3.7
addons:
apt:
sources: *sources
packages:
- clang-3.7
- libncurses5-dev
- os: linux
env: COMPILER_NAME=clang CXX=clang++-3.6 CC=clang-3.6
addons:
apt:
sources: *sources
packages:
- clang-3.6
- libncurses5-dev
before_script:
- mkdir -p build
- cd build
script:
- cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make && make runtests
At this point I feel like I am missing something obvious. I cannot find any solution to this problem (or simply don't know how to search for it effectively).
I feel I should mention that if I swap the gcc section with one of the clang sections that the clang section will fail and the gcc section will pass.
If I can provide anymore useful information then let me know! Thanks in advance for your help.
Simply misspelled sources in the first entry. Corrected that and removed the back referencing and everything is working.