"pkg-config not found" errors using Meson when trying to use the SFML library (Windows)
00:55 23 Dec 2024

I'm trying to run Meson with SFML as a dependency.

I get the message

Did not find pkg-config by name 'pkg-config'

and the error

Dependency lookup for openal with method 'pkgconfig' failed: Pkg-config for machine host machine not found. Giving up."

My meson.build code:

project('meson_test', 'cpp',
        version : '1.0.0',
        default_options : ['warning_level=3', 'cpp_std=c++17'])

pkg_config_path = 'C:\Program Files\pkg-config'
sfml_dep = dependency('sfml', 'pkg-config')
imgui_dep = dependency('imgui-sfml')
pkg = import('pkgconfig')
lib = library('sfml', dependencies : [sfml])
pkg.generate(lib)

executable('meson_test', 'main.cpp',
           install : true,
           win_subsystem : 'windows',
           dependencies : [sfml_dep, imgui_dep])

The full response:

The Meson build system
Version: 1.6.1
Source dir: C:\Users\username\CLionProjects\meson_test
Build dir: C:\Users\username\CLionProjects\meson_test\buildDir
Build type: native build
Project name: meson_test
Project version: 1.0.0
C++ compiler for the host machine: c++ (gcc 6.3.0 "c++ (MinGW.org GCC-6.3.0-1) 6.3.0")
C++ linker for the host machine: c++ ld.bfd 2.28
Host machine cpu family: x86
Host machine cpu: x86
Did not find pkg-config by name 'pkg-config'
Found pkg-config: NO
Found CMake: C:\Program Files\CMake\bin\cmake.EXE (3.30.0)
Run-time dependency sfml found: NO (tried pkgconfig and cmake)
Run-time dependency pkg-config found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency sfml

Executing subproject sfml

sfml| Project name: sfml
sfml| Project version: 2.6.2
sfml| C++ compiler for the host machine: c++ (gcc 6.3.0 "c++ (MinGW.org GCC-6.3.0-1) 6.3.0")
sfml| C++ linker for the host machine: c++ ld.bfd 2.28
sfml| Run-time dependency openal found: NO (tried cmake)

subprojects\SFML-2.6.2\meson.build:14:13: ERROR: Dependency lookup for openal with method 'pkgconfig' failed: Pkg-config for machine host machine not found. Giving up.

My compiler is MinGW and my IDE is CLion.

I tried various ways of downloading pkg-config to my Windows machine, I added pkg-config to PATH and even made a specific env variable called "pkg-config" that links to it. I still can't get Meson to find it.

I'm not having the same issues using SFML with CMAKE.

Also tried this alternate solution:

project('meson_test', 'cpp',
        version : '1.0.0',
        default_options : ['warning_level=3', 'cpp_std=c++17'])

cpp = meson.get_compiler('cpp')
sfml_lib = cpp.find_library('sfml')
pkg_config_path = 'C:\Program Files\pkg-config'
sfml_dep = dependency('sfml', 'pkg-config')
imgui_dep = dependency('imgui-sfml')
pkg = import('pkgconfig')
lib = library('sfml', dependencies : [sfml])
pkg.generate(lib)

executable('meson_test', 'main.cpp',
           install : true,
           win_subsystem : 'windows',
           link_with: sfml_lib,
           include_directories : 'C:\Program Files',
           dependencies : [sfml_dep, imgui_dep])

Response (different error):

The Meson build system
Version: 1.6.1
Source dir: C:\Users\username\CLionProjects\meson_test
Build dir: C:\Users\username\CLionProjects\meson_test\buildDir
Build type: native build
Project name: meson_test
Project version: 1.0.0
C++ compiler for the host machine: c++ (gcc 6.3.0 "c++ (MinGW.org GCC-6.3.0-1) 6.3.0")
C++ linker for the host machine: c++ ld.bfd 2.28
Host machine cpu family: x86
Host machine cpu: x86

meson.build:6:15: ERROR: C++ prefer_static library 'sfml' not found
c++ windows sfml meson-build pkg-config