The Absolute Beginner's Guide to Installing and Using Meson (2024)

This page is meant for people who are new to using Meson and possiblyeven to compiling C and/or C++ code in general. It is meant to containone simple way of getting your build environment up and running. Ifyou are more experienced and have your own preferred way of installingand using development software, feel free to use that instead. Thisguide only deals with Linux, Windows and macOS platforms. If you usesome other platform, such as one of the BSDs, you probably alreadyknow how to install development tools on it (probably better than wedo, even).

There are three phases to getting a development environment running.

  1. Installing a compiler toolchain
  2. Installing Meson
  3. Creating a project and building it

Linux

All Linux distributions provide easy access to development tools.Typically you need to open a terminal and execute one command, whichdepends on your distro.

  • Debian, Ubuntu and derivatives: sudo apt install build-essential
  • Fedora, Centos, RHEL and derivatives: sudo dnf install gcc-c++
  • Arch: sudo pacman -S gcc

Windows

The most common development toolchain on Windows is Visual Studio,which can be downloaded from the Visual Studio website. Select the Communityversion unless you have bought a license.

The Absolute Beginner's Guide to Installing and Using Meson (1)

Download the installer and run it. When you are given a list of thingsto install, select Desktop development with C++. This installs botha C and a C++ compiler.

The Absolute Beginner's Guide to Installing and Using Meson (2)

Once the installer finishes the compiler toolchain is ready to use.

macOS

On macOS the development toolchain must be installed via the Mac appstore. Search for an app called XCode and install it.

The Absolute Beginner's Guide to Installing and Using Meson (3)

Note: Installing XCode is not sufficient by itself. You also need tostart XCode' GUI application once. This will make XCode download andinstall more files that are needed for compilation.

Installing Meson

Linux

Installing Meson is just as simple as installing the compiler toolchain.

  • Debian, Ubuntu and derivatives: sudo apt install meson ninja-build
  • Fedora, Centos, RHEL and derivatives: sudo dnf install meson ninja-build
  • Arch: sudo pacman -S meson

Windows

Meson provides a standard Windows .msi installer that can bedownloaded from the Releasespage.

The Absolute Beginner's Guide to Installing and Using Meson (4)

Download and run it to install all the necessary bits. You can verifythat your installation is working by running the Visual Studiodeveloper tools command prompt that can be found in the start menu.

The Absolute Beginner's Guide to Installing and Using Meson (5)

You should be able to run both meson and ninja and query theirversions.

The Absolute Beginner's Guide to Installing and Using Meson (6)

macOS

With Homebrew

brew install meson ninja

Without Homebrew

Start by downloading the installation package from the Releasespage.

The Absolute Beginner's Guide to Installing and Using Meson (7)

Double click the downloaded installer to start. If you are running anew macOS version, it might refuse to run the application with thefollowing error message:

The Absolute Beginner's Guide to Installing and Using Meson (8)

This can be fixed by starting System Preferences, selecting theSecurity and Privacy entry. At the bottom it shows the blocked app andyou can enable it by clicking on the "Open anyway" button.

The Absolute Beginner's Guide to Installing and Using Meson (9)

Now the installer should start. If not, double click on the downloadedinstaller file again.

The Absolute Beginner's Guide to Installing and Using Meson (10)

Once the installation is finished you can verify that the system is working via the terminal app.

The Absolute Beginner's Guide to Installing and Using Meson (11)

Running Meson

Start a terminal application. On Windows you have to use the VisualStudio Developer Tools Command Prompt as discussed above, because thecompilers are only available in that terminal. You also need to changeinto your home directory (Linux and macOS terminals start in the homedirectory by default).

cd \users\username

Create a new directory to hold your project.

mkdir testprojectcd testproject

Use Meson to create and build a new sample project.

meson init --name testproject --build

This will create a project skeleton for you and compile it. The resultis put in the build subdirectory and can be run directly from there.

build/testproject

The Absolute Beginner's Guide to Installing and Using Meson (12)

The project is now ready for development. You can edit the code withany editor and it is rebuilt by going in the build subdirectory andexecuting the meson compile command. If your version of Meson is tooold, you can compile the project by running the command ninjainstead.

The results of the search are

Website licensing information are available on the Legal page.

The Absolute Beginner's Guide to Installing and Using Meson (2024)
Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 5995

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.