Is it possible to use travis-ci to build a c++ application/project that uses cmake, gcc-6 and g++-6?
Configuring travis to use the right compiler is a bit tricky.
This is how it can be done:
First of all you need to set the distribution to trusty (the newest version of ubuntu that's supported by travis-ci) and require sudo.
dist: trusty
sudo: require
Next up we set the language and the compiler:
language: cpp
compiler: gcc
So far so good. Now we can go about setting up the apt install configuration:
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-6
- g++-6
- cmake
This adds the ppa for the newer version of our build tools and installs them. The next step is setting up links to the new gcc and g++. /usr/local/bin is being searched before /usr/bin, so that our newly installed version 6 compilers are going to be accessible with just gcc and g++. The beginning of your script: should look like this:
script:
- sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
- sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++
Add the next line as well, if you want to verify the versions of those tools:
- gcc -v && g++ -v && cmake --version
The versions that come back from these commands are as follows:
gcc: 6.2.0
g++: 6.2.0
cmake: 3.2.2
That's basically it. The complete .travis.yml looks like this:
dist: trusty
sudo: required
language:
- cpp
compiler:
- gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-6
- g++-6
- cmake
script:
# Link gcc-6 and g++-6 to their standard commands
- ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
- ln -s /usr/bin/g++-6 /usr/local/bin/g++
# Export CC and CXX to tell cmake which compiler to use
- export CC=/usr/bin/gcc-6
- export CXX=/usr/bin/g++-6
# Check versions of gcc, g++ and cmake
- gcc -v && g++ -v && cmake --version
# Run your build commands next
I found some errors in #henne90gen's answer (or maybe they've just changed). Specifically:
You don't need sudo.
You don't need to install CMake from apt. This will install an ancient CMake 2.8 from Trusty. Fortunately the build image already comes with CMake 3.9.2 (as of now).
gcc-7 doesn't get installed to /usr/local/bin and it is already in the PATH.
This should work:
dist: trusty
language: cpp
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-7
- g++-7
script:
- export CC=gcc-7
- export CXX=g++-7
- ...
Here's a longer example that includes a modern version of Qt (with QtSVG which I'm using), and works on OSX and Linux.
os:
- linux
- osx
language: cpp
dist: trusty
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- sourceline: "ppa:beineri/opt-qt-5.10.1-trusty"
packages:
- gcc-7
- g++-7
- qt510-meta-minimal
- qt510svg
- qt510imageformats
- qt510tools
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update ;
brew install qt5 cmake ;
brew link --force qt ;
fi
script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
export CC=gcc-7 ;
export CXX=g++-7 ;
source /opt/qt510/bin/qt510-env.sh ;
fi
- cmake --version
- qmake --version
- ...
Use dist: bionic. This should meet most of the cases.
Adding a semi-related solution after struggling with this for way too long. Hopefully, it helps someone else avoid spending the amount of time I did going through the cycle of updating travis.yml, committing, waiting for Travis...repeat til it works.
I had a C extension in a Python project that started producing failing tests in Travis, yet passed locally. Eventually, I tracked it down to the old version of gcc on the xenial environment. Here's the Travis YAML file that finally solved the issue for me:
dist: xenial
language: python
before_install:
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update -q
- sudo apt-get install -y gcc-7
- export CC=/usr/bin/gcc-7
python:
- "3.6"
- "3.7"
install:
- pip install -r requirements.txt
- python setup.py build_ext --inplace
script:
- python run_tests.py
As an aside, anyone else find they want to trigger a Travis build on a specific commit to find out exactly where a problem started?
Related
I have an PyQt5 project on github, and the following is my environment settings:
dist: trusty
sudo: required
language: python
python:
- 3.4
- 3.5
before_install:
#SIP
- cd ..
- curl -L -O "https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.3/sip-4.19.3.tar.gz"
- tar -xvf sip-4.19.3.tar.gz
- cd sip-4.19.3
- python configure.py
- sudo make install
#Qt5
- sudo add-apt-repository -y "ppa:beineri/opt-qt59-trusty"
- sudo apt-get update -qq
- sudo apt-get install qt59-meta-full qt59charts-no-lgpl
- QTDIR="/opt/qt59"
- PATH="$QTDIR/bin:$PATH"
- source /opt/qt59/bin/qt59-env.sh
- qmake -v
#PyQt5
- cd ..
- curl -L -O "https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.9/PyQt5_gpl-5.9.tar.gz"
- tar -xvf PyQt5_gpl-5.9.tar.gz
- cd PyQt5_gpl-5.9
- python configure.py --confirm-license
- sudo make install
#QScintilla
- cd ..
- curl -L -O "https://sourceforge.net/projects/pyqt/files/QScintilla2/QScintilla-2.10.1/QScintilla_gpl-2.10.1.tar.gz"
- tar -xvf QScintilla_gpl-2.10.1.tar.gz
- cd QScintilla_gpl-2.10.1
- cd Qt4Qt5
- qmake qscintilla.pro
- sudo make install
- cd ../designer-Qt4Qt5
- qmake designer.pro
- sudo make install
- cd ../Python
- python configure.py --pyqt=PyQt5
- sudo make install
#PyQtChart
- cd ../..
- curl -L -O "https://sourceforge.net/projects/pyqt/files/PyQtChart/PyQtChart-5.9/PyQtChart_gpl-5.9.tar.gz"
- tar -xvf PyQtChart_gpl-5.9.tar.gz
- cd PyQtChart_gpl-5.9
- python configure.py
- sudo make install
- cd $TRAVIS_BUILD_DIR
install:
- pip install -r requirements.txt
- pip install pyinstaller
script:
- make
before_cache:
- rm -rf $HOME/.cache/pip/log
cache:
directories:
- $HOME/.cache/pip
My project requires SIP, PyQt 5.7 or higher (for PyQtChart), QScintilla and some python modules.
One can imagine that it has been more than 50 minutes.
Is there any way to make these steps faster?
This is more of a workaround than a proper fix, but I've been using miniconda to successfully install pyqt for me. This isn't super fast but is a lot faster than what you're currently doing.
The following lines will get you into a python virtual environment with pyqt installed:
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
bash ./miniconda.sh -b -p ${HOME}/miniconda;
export PATH=${HOME}/miniconda/bin:$PATH;
conda install --yes python="2.7" pyqt;
Another solution could be using the unofficial PyPI exposed and maintained here: https://github.com/pyqt/python-qt5
By running pip install python-qt5. Keep in mind this is not official and may break/disfunction. Use at your own risk.
Additionally, keep in mind that with python 3.5 and up, you can install pyqt5 using pip by simply running
pip3 install pyqt5
Last but not least, Travis' maintainers may be willing to add pyqt builds as part of their own environments, either pre-installed or available as precompiled binaries for installation using pip.
I'll +1 any such request.
I need to speed up a travis package generation in which I need
brew install fftw --with-openmp
that takes ~20 minutes to build and most of the time Travis kills my job.
My idea is to create another repo in which (once in a while) I generate the binary bottled version of fftw --with-openmp and then from my application repo intall that particular bottled version. I'm stuck in this last part...
I created an empty repo linked to travis (https://github.com/iltommi/fftw-openmp) in which I just have a .travis.yml :
os: osx
osx_image: xcode7.1
sudo: required
script:
- export COMPILER=g++-6
- brew update; brew tap homebrew/science
- brew install --build-bottle fftw --with-openmp
- brew bottle fftw
- export RELEASE_FILE=$(ls fftw*bottle*.tar.gz)
- ls -la
deploy:
provider: releases
edge:
branch: releases-fix
api_key: $github_token
file: "${RELEASE_FILE}"
skip_cleanup: true
overwrite: true
So I get a file in the releases (https://github.com/iltommi/fftw-openmp/releases)
Now, How do I install from my other repo?
I can get it via wget but then?
Thanks
It looks like it has been answered here https://apple.stackexchange.com/a/204833/99311:
I'll leave this in case someone else need this on stackoverflow:
brew install -f fftw-3.3.5.yosemite.bottle.1.tar.gz
where fftw-3.3.5.yosemite.bottle.1.tar.gz is the file generated by the commands
brew install --build-bottle fftw --with-openmp
brew bottle fftw
I am using CentOS 7.2
When I use yum groupinstall "Development Tools", gcc version is 4.8.5, like this:
I would like to install gcc 5.3
How to approach this with yum?
Update:
Often people want the most recent version of gcc, and devtoolset is being kept up-to-date, so maybe you want devtoolset-N where N={4,5,6,7...}, check yum for the latest available on your system). Updated the cmds below for N=7.
There is a package for gcc-7.2.1 for devtoolset-7 as an example. First you need to enable the Software Collections, then it's available in devtoolset-7:
sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
which gcc
gcc --version
Update: Installing latest version of gcc 9: (gcc 9.3.0) - released March 12, 2020:
Same method can be applied to gcc 10 (gcc 10.1.0) - released May 7, 2020
Download file: gcc-9.3.0.tar.gz or
gcc-10.1.0.tar.gz
Compile and install:
//required libraries: (some may already have been installed)
dnf install libmpc-devel mpfr-devel gmp-devel
//if dnf install libmpc-devel is not working try:
dnf --enablerepo=PowerTools install libmpc-devel
//install zlib
dnf install zlib-devel*
./configure --with-system-zlib --disable-multilib --enable-languages=c,c++
make -j 8 <== this may take around an hour or more to finish
(depending on your cpu speed)
make install
Tested under CentOS 7.8.2003 for gcc 9.3 and gcc 10.1
Tested under CentOS 8.1.1911 for gcc 10.1 (may take more time to compile)
Results: gcc/g++ 9.3.0/10.1.0
Installing gcc 7.4 (gcc 7.4.0) - released December 6, 2018:
Download file: https://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
Compile and install:
//required libraries:
yum install libmpc-devel mpfr-devel gmp-devel
./configure --with-system-zlib --disable-multilib --enable-languages=c,c++
make -j 8 <== this may take around 50 minutes or less to finish with 8 threads
(depending on your cpu speed)
make install
Result:
Notes:
1. This Stack Overflow answer will help to see how to verify the downloaded source file.
2. Use the option --prefix to install gcc to another directory other than the default one. The toplevel installation directory defaults to /usr/local. Read about gcc installation options
You can use the centos-sclo-rh-testing repo to install GCC v7 without having to compile it forever, also enable V7 by default and let you switch between different versions if required.
sudo yum install -y yum-utils centos-release-scl;
sudo yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc;
echo "source /opt/rh/devtoolset-7/enable" | sudo tee -a /etc/profile;
source /opt/rh/devtoolset-7/enable;
gcc --version;
The best approach to use yum and update your devtoolset is to utilize the CentOS SCLo RH Testing repository.
yum install centos-release-scl-rh
yum --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc devtoolset-7-gcc-c++
Many additional packages are also available, to see them all
yum --enablerepo=centos-sclo-rh-testing list devtoolset-7*
You can use this method to install any dev tool version, just swap the 7 for your desired version. devtoolset-6-gcc, devtoolset-5-gcc etc.
Command to install GCC and Development Tools on a CentOS / RHEL 7 server
Type the following yum command as root user:
yum group install "Development Tools"
OR
sudo yum group install "Development Tools
If above command failed, try:
yum groupinstall "Development Tools
I would like to use an old version of gcc for one of my program (versions 3.* would be good), any idea how to do this?
Just compile and install it somewhere and optionally add its location to your $PATH. Do this in a directory where you downloaded gcc source code:
$ contrib/download_prerequisites
$ cd ..
$ mkdir objdir
$ cd objdir
$ ../gcc/configure --enable-languages=c --disable-multilib --prefix=$HOME/gcc-4.6.2 # modify option to suit your needs
$ make -j8
$ make install
Run it in $HOME/gcc-4.6.2:
$ usr/local/bin/gcc --version
(or use make install DESTDIR=<DIR> instead of --prefix)
If you are trying to install an older version of GCC that is no longer available (i.e. gcc 4.9) on ubuntu, you will not be able to download it directly.
Open your /etc/apt/sources.list file and append the following two lines:
deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe
If this is your first time installing versioning on GCC run:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
Then in your terminal run the installation for any versions you are attempting to add. For example, if you want to install 4.9 (outdated) alongside gcc 7 and gcc 8 (not outdated):
Sources: How to install GCC Compiler on Ubuntu 18.04I need to install gcc4.9 on ubuntu 20.04|matlab mex
sudo apt update
sudo apt install gcc-4.9 g++ 4.9 gcc-7 g++-7 gcc-8 g++-8
Next, configure the GCC alternatives and their priority level:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 49 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8
To compile your code using one of the newly installed versions, simply specify at compile time:
g++-4.9 <file_name>.cpp
To set your default GCC compiler use:
sudo update-alternatives --config gcc
Note: If this is your first time installing any version of GCC you may need to run
sudo apt install build-essential
sudo apt-get install manpages-dev
Sources: How to install GCC Compiler on Ubuntu 18.04
I need to install gcc4.9 on ubuntu 20.04|matlab mex
I'm using codeblocks with fedora-16. When I try to build it starts the build but then says `"/bin/sh: g++ command not found".
If I select compile, it compiles OK.
So looking at this site they say that gcc uses g++ so I tried "gcc -c this.c" and that worked.
Does anyone have a clue as to what is going on?
In order to compile .c and .cpp files in Fedora you need to install a compiler.
To install the gcc and g++ compilers, you will need the build-essential package. This will also install GNU make.
build-essential contains a list of packages which are essential for building Ubuntu packages including gcc compiler, make and other required tools.
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
$ gcc -v
$ make -v
Now, you should able to compile software using C / C++ compilers.
To install the manpages for c and c++ development, install the manpages-dev package.
If
$ sudo apt-get install build-essential
doesn't work, try this:
su -
yum install make automake gcc gcc-c++ kernel-devel
Codeblock invokes g++ to link the libraries.