Meson and threads

on , , , , 1 minute reading

Some time ago I wrote a small piece about using the Thread dependencies in CMake and if I remember correctly it was a little tricky to set the correct threads library (Unix systems has a pthreads library, for example). Guess what? is super easy to do it in Meson!

Let’s see the example from that post:

#include <iostream>
#include <thread>

int main() {
    std::thread t([] {
        std::cout << "hello concurrent world!\n";

The Meson build file couldn’t be simpler:

project('meson_conan', 'cpp', default_options: ['cpp_std=c++17'])

threads = dependency('threads')

executable('demo', 'main.cpp', dependencies: [threads])

Notice the dependency name should be threads, Meson will know the correct library to pick dependending on the operating system, nothing to worry about!