Use C/C++ with Travis CI

The following is a guide to getting started with Travis CI using C/C++.

Prerequisite #

Before getting started, create a .travis.yml file and add it to the root directory of your C/C++ project.

Specify the Language #

Define C/C++ as the chosen language and specify which compiler to use.

Open your file and enter:

language: c
compiler:
  - gcc
  - clang

Install Build Dependencies #

Now is the time to install any necessary packages, like build tools or libraries, to the project. Use the before_install section to add the following command:

before_install:
  - sudo apt-get update
  - sudo apt-get install -y build-essential

Configure your File #

Define the build and specify any test command to compile and run tests. Use the script section to specify any commands. Below is an example using a Makefile:

script:
  - make

Commit and Push #

Once the file is set up, commit it to your repository, and Travis begins building and testing your C/C++ project. By the end, your file should look like this:

language: c
compiler:
  - gcc
  - clang
before_install:
  - sudo apt-get update
  - sudo apt-get install -y build-essential
script:
  - make

Further Reading #

For more information on C and C++ projects see: