How to integrate Vcpkg with Meson Build system
Table of Contents
Photo by @theshubhamdhage from Unsplash.com
The worst part about developing on Windows is developing on Windows. Okay, jokes aside, life is generally easier on Linux.
On Linux, package management is typically handled by the OS. You just download the library with the -devel suffix, and in meson.build, you add the dependency() function to link it to your program.
On Windows, however, you often find yourself hunting for sketchy installers, manually wiring up INCLUDE and LIB paths, or dealing with the dreaded “DLL hell”.
So, how do we get Vcpkg (which handles the messy downloading part) to play nice with Meson (which handles our build configuration)? The secret sauce is a native-file.
The Native File
If you haven’t used it, Vcpkg is Microsoft’s C/C++ package manager. To make it talk to Meson, we need a “Native File”.
Think of this file as a bridge. It tells Meson specific details about your machine, like where to find the pkg-config executable. Since Vcpkg actually generates pkg-config files for the libraries it installs, pointing Meson to Vcpkg’s internal pkgconf.exe makes standard dependency() calls work like magic.
Here is the native file content:
|
|
Save it somewhere (I named it meson-vcpkg.txt and placed it in the same folder as the meson.build file).
Important: Modify vcpkg_base_path and vcpkg_base_install_dir inside the file so that they point to your actual Vcpkg installation folder.
Manifest Mode
I used to install packages manually via the command line (e.g., vcpkg install sdl3), but these days I strongly recommend using Manifest Mode. It keeps your project entirely self-contained and guarantees that anyone who clones your repo gets the exact same dependencies without any headaches.
Create a vcpkg.json in your project root:
|
|
Add your dependencies under “dependencies”. I added SDL3, libyaml, and pkgconf (which is required for the integration to work) as examples.
The Build File
Now, set up your meson.build to consume these packages. Notice how clean it is—no hardcoded paths!
|
|
Building the Project
Finally, configure the build folder. We pass the --native-file argument to tell Meson about our Vcpkg configuration.
|
|
Example output:
|
|
It will automatically invoke Vcpkg to install the dependencies listed in vcpkg.json before the build starts.
Troubleshooting
Missing DLLs
If you’re anything like me, you might run into a wall where your compiled program crashes immediately at startup, complaining about missing .dll files.
This happens because Windows loads dynamic libraries from the executable’s directory or the system PATH. Vcpkg builds dynamic libraries by default, but it doesn’t automatically copy them to your output folder.
Solution: You need to copy all the necessary DLL files into the build folder (where your executable is located).
Demonstration
If you want to see all of this put together in a real project, I’ve set up a working example over on my GitHub repo.