I'm preparing to compile a GTK+-3.0 test application on Windows 11. I have a CMake configuration that runs well on linux.
I've installed GTK 3.0 with msys2, following this instruction: https://www.gtk.org/docs/installations/windows/
I've updated the global environment variable PATH
(appending C:\tools\msys64\mingw64\bin
) and I've created the global environment variable PKG_CONFIG_PATH
, containing the path to the directory with all the .pc files (C:\tools\msys64\mingw64\lib\pkgconfig
). When I run pkg-config.exe --list-all
, the list contains GTK+-3.0 and running pkg-config.exe --print-variables --debug gtk+-3.0
gives a reasonable output without any errors.
I am using this in my CMake configuration:
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET "gtk+-3.0")
On Windows, I am getting the error:
-- Checking for module 'gtk+-3.0'
-- Package 'gtk+-3.0', required by 'virtual:world', not found
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules FindPkgConfig.cmake:607 (message):
A required package was not found
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.25/Modules FindPkgConfig.cmake:829 (_pkg_check_modules_internal)
CMakeLists.txt:35 (pkg_check_modules)
While I was experimenting with the configuration of the environment variables, I was getting the same error, every time the PKG_CONFIG_PATH
was not pointing to the directory containing the file gtk+-3.0.pc
. It seems to me, that required by 'virtual:world', not found
is more of a generic error for a missing .pc file than actually a missing requirement.
I have already been looking at this article: set PKG_CONFIG_PATH in cmake but the proposed solution didn't help me. When I set the environment variable PKG_CONFIG_PATH
in the CMake configuration too, I'm still getting the same error.
I do not use Windows very often at all. It is not unlikely, that I've been missing something that's very obvious to an experienced Windows user.
Either calling CMake from the MSYS2 environment or additionally setting the global environment variable MSYSTEM when calling the windows installation of CMake from Windows command prompt, both worked for me to solve this issue.
Calling CMake from the MSYS2 environment seems to be the easier and more recommendable option here.