travis ci make -std=c++14 not recognized - c++

I have the error g++: error: unrecognized command line option ‘-std=c++14’ when building my project with travis ci using premake (https://travis-ci.org/S6066/Teal/builds/171980872)
My premake script: https://github.com/S6066/Teal/blob/master/build/premake5.lua
My travis ci file: https://github.com/S6066/Teal/blob/master/.travis.yml
Thanks for help.
Edit: g++ --version gives me 4.8.5, so the real problem is Travis won't compile with g++ 6

I did these scripts for a github project and c++14 works:
This is an example of a .travis.yml:
sudo: required
dist: trusty
language: cpp
compiler: g++
install: export CXX="g++-5"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5
notifications:
email:
on_success: never
on_failure: always
before_install: sudo apt-get update -qq
script: make --directory "Var & ReadOnly C++"
And this is the associated makefile:
all:
$(CXX) -std=c++14 main.cpp -I . -Os -Wall -Wextra -o Example
clean:
rm Example*

Related

How to compile custom cpp files on Google Colab

I'm trying to replicate the result of this github repo using Google Colab since I don't want to install all the requirements on my local machine and to take advantage of the GPU on Google Colab
However, one of the things I need to do (as indicated in the repo's README) is to first compile a cpp makefile. The instruction of the makefile is included below. Obvious I can't follow this instruction since I don't know Google Colab's directories of ncvv, cudalib and tensorflow library
cd latent_3d_points/external
with your editor modify the first three lines of the makefile to point to
your nvcc, cudalib and tensorflow library.
make
Is there a way for me to compile the files included in the makefile (because those functions are needed to run the model) either using the makefile directly or compile each cpp file individually? I included the content of the makefile below to avoid having you to click around in the repo looking for it
nvcc = /usr/local/cuda-8.0/bin/nvcc
cudalib = /usr/local/cuda-8.0/lib64
tensorflow = /orions4-zfs/projects/optas/Virt_Env/tf_1.3/lib/python2.7/site-packages/tensorflow/include
all: tf_approxmatch_so.so tf_approxmatch_g.cu.o tf_nndistance_so.so tf_nndistance_g.cu.o
tf_approxmatch_so.so: tf_approxmatch_g.cu.o tf_approxmatch.cpp
g++ -std=c++11 tf_approxmatch.cpp tf_approxmatch_g.cu.o -o tf_approxmatch_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_CXX11_ABI=0
tf_approxmatch_g.cu.o: tf_approxmatch_g.cu
$(nvcc) -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o tf_approxmatch_g.cu.o tf_approxmatch_g.cu -I $(tensorflow) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
tf_nndistance_so.so: tf_nndistance_g.cu.o tf_nndistance.cpp
g++ -std=c++11 tf_nndistance.cpp tf_nndistance_g.cu.o -o tf_nndistance_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_CXX11_ABI=0
tf_nndistance_g.cu.o: tf_nndistance_g.cu
$(nvcc) -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -c -o tf_nndistance_g.cu.o tf_nndistance_g.cu -I $(tensorflow) -DGOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -O2
clean:
rm tf_approxmatch_so.so
rm tf_nndistance_so.so
rm *.cu.o
You can use the bash like on your pc by adding %%bash in the colab's cells.
Example:
Cell one: write cpp file
%%writefile welcome.cpp
#include <iostream>
int main()
{
std::cout << "Welcome To AI with Ashok's Blog\n";
return 0;
}
Cell two: compile and run
%%bash
g++ welcome.cpp -o welcome
./welcome
You can also open the cpp file in colab's build-in text editor in order to enjoy correct highlights. It opens when you open a text file from the "Files" tab on the left and can be save with "ctr+s" shortcut.
You can install the required version of Cuda in google colab. For eg.
For Cuda 9.2 you can try
!apt-get --purge remove cuda nvidia* libnvidia-*
!dpkg -l | grep cuda- | awk '{print $2}' | xargs -n1 dpkg --purge
!apt-get remove cuda-*
!apt autoremove
!apt-get update
!wget https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64 -O cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
!dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb
!apt-key add /var/cuda-repo-9-2-local/7fa2af80.pub
!apt-get update
!apt-get install cuda-9.2
Similarly, you can find a way to install Cuda 8.2.
For gcc
!apt-get install -qq gcc-5 g++-5 -y
!ln -s /usr/bin/gcc-5
!ln -s /usr/bin/g++-5
!sudo apt-get update
!sudo apt-get upgrade
Then you can compile it or make it by running make, if your installation has a custom make file.
!make

CMAKE_CXX_COMPILER_VERSION is pointing to the old GCC version

I have upgraded my GCC using:
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install gcc-8 g++-8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 70 --slave /usr/bin/g++ g++ /usr/bin/g++-8
Running any of these commands:
$ gcc --version
$ g++ --version
$ c++ --version
$ /usr/bin/gcc --version
$ /usr/bin/g++ --version
$ /usr/bin/c++ --version
would show (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0 confirming that version 8.1 has been installed.
When running ./configure on cmake-3.12.1 I downloaded from its website I get:
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
However when trying to make my actual project:
CMake Error at CMakeLists.txt:24 (message):
GCC version must be at least 7.1! 5.4.0
This is my CMakeLists.txt:
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# require at least gcc 7.1
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1)
message(FATAL_ERROR "GCC version must be at least 7.1! " ${CMAKE_CXX_COMPILER_VERSION})
endif()
endif()
As Shawn, Tsyvarev and hellow have mentioned in the comments, this problem is caused by CMake cache file which was located inside /build/. Deleting the file solved the issue.

gitlab-ci.yml cpp coverage report

I am trying to implement CI using Gitlab for a c++ project. To start with, I added a simple c++ hello world program which compiled and ranfine in both my PC and in Gitlab CI.
When I try to generate coverage report for the same the commands, it works on PC but not in Gitlab CI.
This is my gitlab-ci.yml
# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: gcc
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
# before_script:
# - apt update && apt -y install make autoconf
script:
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ls
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- bash runmytests.sh
coverage:
stage: deploy
before_script:
- apt-get -qq update && apt-get -qq install -y gcovr ggcov lcov
script:
- ls
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ./mybinary
- ls
- gcov helloworld.cpp
- lcov --directory . --capture --output-file coverage.info
- lcov --remove coverage.info '/usr/*' --output-file coverage.info
- lcov --list coverage.info
- genhtml -o res coverage.info
This is the generated error output
$ g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
$ ./mybinary
Hello, World!$ ls
README.md
helloworld.cpp
helloworld.gcda
helloworld.gcno
mybinary
runmytests.sh
$ gcov helloworld.cpp
File 'helloworld.cpp'
Lines executed:100.00% of 3
Creating 'helloworld.cpp.gcov'
File '/usr/local/include/c++/8.1.0/iostream'
No executable lines
Removing 'iostream.gcov'
$ lcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 8.1.0
Scanning . for .gcda files ...
geninfo: WARNING: /builds/ganeshredcobra/gshell/helloworld.gcno: Overlong record at end of file!
Found 1 data files in .
Processing helloworld.gcda
geninfo: WARNING: cannot find an entry for helloworld.cpp.gcov in .gcno file, skipping file!
Finished .info-file creation
$ lcov --list coverage.info
Reading tracefile coverage.info
lcov: ERROR: no valid records found in tracefile coverage.info
ERROR: Job failed: exit code 1
How can I fix this?
Solved the issue by changing image name from gcc to ubuntu 16.04, the working yml will look like this
# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: ubuntu:16.04
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
before_script:
- apt update && apt -y install make autoconf gcc g++
script:
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ls
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- bash runmytests.sh
coverage:
stage: deploy
before_script:
- apt-get -qq update && apt-get -qq install -y make autoconf gcc g++ gcovr ggcov lcov
script:
- ls
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ./mybinary
- ls
- gcov helloworld.cpp
- lcov --directory . --capture --output-file coverage.info
- lcov --list coverage.info

header file <execution> missing in gcc 7.2 (Ubuntu) : how to solve it?

few days ago I updated in my Ubuntu 16.04 Server Edition gcc to gcc 7.2 version:
gcc version 7.2.0 (Ubuntu 7.2.0-1ubuntu1~16.04)
which should be the most updated version of gcc available for Ubuntu
Now, compiling an example of a book,
g++ -std=c++17 auto_parallel.cpp -oauto_parallel
auto_parallel.cpp:5:10: fatal error: execution: No such file or directory
include <execution>
~~~~~~~~~~
compilation terminated.
How to solve the problem?
Thanks in advance. Marco
update your GUN compiler to version9, according to(https://en.cppreference.com/w/cpp/compiler_support
and https://www.bojankomazec.com/2020/03/upgrading-gnu-cc-compilers-on-ubuntu.html)
sudo apt install -y gcc-9 g++-9 -y
and remap your compiler to gcc-9
sudo rm /usr/bin/g++
sudo ln -s /usr/bin/g++-9 /usr/bin/g++
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-9 /usr/bin/gcc
Verify the compiler version
ls -la /usr/bin/gcc
ls -la /usr/bin/g++

While installing on OSX Sierra via gcc-6, keep having "FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!" error

Environment info
Operating System:
macOS 10.12.2 (16C68)
Compiler:
gcc-6
Steps to reproduce
I've installed gcc-6 and modified config.mk as required into
export CC = gcc-6
export CXX = g++-6
But keep having this error:
g++-6 -c -std=c++0x -Wall -Wno-unknown-pragmas -Iinclude -Idmlc-core/include -Irabit/include -O3 -funroll-loops -msse2 -fPIC -fopenmp src/learner.cc -o build/learner.o
FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
What have you tried?
Reinstall XCode
Reinstall gcc
Run make clean_all && make -4j
But still went wrong. Any idea?
I had this issue when using macports-installed gnu assembler. You could try forcing the use of as that comes with Xcode, or simply temporarily removing /opt/local/bin from your path.
I solved by uninstalling MacPorts:
sudo port -f uninstall installed