This page shows from the ground up how to create a Meson build definition for a simple project. Then we expand it to use external dependencies to show how easily they can be integrated into your project.
The humble beginning
-----
Let's start with the most basic of programs, the classic hello example. First we create a file `main.c` which holds the source. It looks like this.
```c
#include<stdio.h>
int main(int argc, char **argv) {
printf("Hello there.\n");
return 0;
}
```
Then we create a Meson build description and put it in a file called `meson.build` in the same directory. Its contents are the following.
That is all. We are now ready to build our application. First we need to initialize the build by going into the source directory and issuing the following commands.
We create a separate build directory to hold all of the compiler output. Meson is different from some other build systems in that it does not permit in-source builds. You must always create a separate build directory. Common convention is to put the default build directory in a subdirectory of your top level source directory.
Just printing text is a bit old fashioned. Let's update our program to create a graphical window instead. We'll use the [GTK+](https://gtk.org) widget toolkit. First we edit the main file to use GTK+. The new version looks like this.
Now we are ready to build. The thing to notice is that we do *not* need to recreate our build directory, run any sort of magical commands or the like. Instead we just type the exact same command as if we were rebuilding our code without any build system changes.
```
$ ninja
```
Once you have set up your build directory the first time, you don't ever need to run the `meson` command again. You always just run `ninja`. Meson will automatically detect when you have done changes to build definitions and will take care of everything so users don't have to care. In this case the following output is produced.