| 1 |
--- |
| 2 |
short-description: Simple getting started guide |
| 3 |
... |
| 4 |
|
| 5 |
# The Absolute Beginner's Guide to Installing and Using Meson |
| 6 |
|
| 7 |
This page is meant for people who are new to using Meson and possibly |
| 8 |
even to compiling C and/or C++ code in general. It is meant to contain |
| 9 |
one simple way of getting your build environment up and running. If |
| 10 |
you are more experienced and have your own preferred way of installing |
| 11 |
and using development software, feel free to use that instead. This |
| 12 |
guide only deals with Linux, Windows and macOS platforms. If you use |
| 13 |
some other platform, such as one of the BSDs, you probably already |
| 14 |
know how to install development tools on it (probably better than we |
| 15 |
do, even). |
| 16 |
|
| 17 |
There are three phases to getting a development environment running. |
| 18 |
|
| 19 |
1. Installing a compiler toolchain |
| 20 |
2. Installing Meson |
| 21 |
3. Creating a project and building it |
| 22 |
|
| 23 |
## Installing a compiler toolchain |
| 24 |
|
| 25 |
### Linux |
| 26 |
|
| 27 |
All Linux distributions provide easy access to development tools. |
| 28 |
Typically you need to open a terminal and execute one command, which |
| 29 |
depends on your distro. |
| 30 |
|
| 31 |
- Debian, Ubuntu and derivatives: `sudo apt install build-essential` |
| 32 |
- Fedora, Centos, RHEL and derivatives: `sudo dnf install gcc-c++` |
| 33 |
- Arch: `sudo pacman -S gcc` |
| 34 |
|
| 35 |
### Windows |
| 36 |
|
| 37 |
The most common development toolchain on Windows is Visual Studio, |
| 38 |
which can be downloaded from [the Visual Studio web |
| 39 |
site](https://visualstudio.microsoft.com/). Select the Community |
| 40 |
version unless you have bought a license. |
| 41 |
|
| 42 |
 |
| 43 |
|
| 44 |
Download the installer and run it. When you are given a list of things |
| 45 |
to install, select *Desktop development with C++*. This installs both |
| 46 |
a C and a C++ compiler. |
| 47 |
|
| 48 |
 |
| 49 |
|
| 50 |
Once the installer finishes the compiler toolchain is ready to use. |
| 51 |
|
| 52 |
### macOS |
| 53 |
|
| 54 |
On macOS the development toolchain must be installed via the Mac app |
| 55 |
store. Search for an app called XCode and install it. |
| 56 |
|
| 57 |
 |
| 58 |
|
| 59 |
*Note:* Installing XCode is not sufficient by itself. You also need to |
| 60 |
start XCode' GUI application once. This will make XCode download and |
| 61 |
install more files that are needed for compilation. |
| 62 |
|
| 63 |
## Installing Meson |
| 64 |
|
| 65 |
### Linux |
| 66 |
|
| 67 |
Installing Meson is just as simple as installing the compiler toolchain. |
| 68 |
|
| 69 |
- Debian, Ubuntu and derivatives: `sudo apt install meson ninja-build` |
| 70 |
- Fedora, Centos, RHEL and derivatives: `sudo dnf install meson ninja-build` |
| 71 |
- Arch: `sudo pacman -S meson` |
| 72 |
|
| 73 |
### Windows |
| 74 |
|
| 75 |
Meson provides a standard Windows `.msi` installer that can be |
| 76 |
downloaded from [the Releases |
| 77 |
page](https://github.com/mesonbuild/meson/releases). |
| 78 |
|
| 79 |
 |
| 80 |
|
| 81 |
Download and run it to install all the necessary bits. You can verify |
| 82 |
that your installation is working by running the Visual Studio |
| 83 |
developer tools command prompt that can be found in the start menu. |
| 84 |
|
| 85 |
 |
| 86 |
|
| 87 |
You should be able to run both `meson` and `ninja` and query their |
| 88 |
versions. |
| 89 |
|
| 90 |
 |
| 91 |
|
| 92 |
### macOS |
| 93 |
|
| 94 |
#### With Homebrew |
| 95 |
`brew install meson ninja` |
| 96 |
|
| 97 |
#### Without Homebrew |
| 98 |
Start by downloading the installation package from [the Releases |
| 99 |
page](https://github.com/mesonbuild/meson/releases). |
| 100 |
|
| 101 |
 |
| 102 |
|
| 103 |
Double click the downloaded installer to start. If you are running a |
| 104 |
new macOS version, it might refuse to run the application with the |
| 105 |
following error message: |
| 106 |
|
| 107 |
 |
| 108 |
|
| 109 |
This can be fixed by starting System Preferences, selecting the |
| 110 |
Security and Privacy entry. At the bottom it shows the blocked app and |
| 111 |
you can enable it by clicking on the "Open anyway" button. |
| 112 |
|
| 113 |
 |
| 114 |
|
| 115 |
Now the installer should start. If not, double click on the downloaded |
| 116 |
installer file again. |
| 117 |
|
| 118 |
 |
| 119 |
|
| 120 |
Once the installation is finished you can verify that the system is working via the terminal app. |
| 121 |
|
| 122 |
 |
| 123 |
|
| 124 |
## Running Meson |
| 125 |
|
| 126 |
Start a terminal application. On Windows you have to use the Visual |
| 127 |
Studio Developer Tools Command Prompt as discussed above, because the |
| 128 |
compilers are only available in that terminal. You also need to change |
| 129 |
into your home directory (Linux and macOS terminals start in the home |
| 130 |
directory by default). |
| 131 |
|
| 132 |
cd \users\username |
| 133 |
|
| 134 |
Create a new directory to hold your project. |
| 135 |
|
| 136 |
mkdir testproject |
| 137 |
cd testproject |
| 138 |
|
| 139 |
Use Meson to create and build a new sample project. |
| 140 |
|
| 141 |
meson init --name testproject --build |
| 142 |
|
| 143 |
This will create a project skeleton for you and compile it. The result |
| 144 |
is put in the `build` subdirectory and can be run directly from there. |
| 145 |
|
| 146 |
build/testproject |
| 147 |
|
| 148 |
 |
| 149 |
|
| 150 |
The project is now ready for development. You can edit the code with |
| 151 |
any editor and it is rebuilt by going in the `build` subdirectory and |
| 152 |
executing the `meson compile` command. If your version of Meson is too |
| 153 |
old, you can compile the project by running the command `ninja` |
| 154 |
instead. |