Problem finding library with CMake pkg_check_modules (in CLion) while pkg-config works fine (outside of CLion)

Viewed 35

I'm trying to learn libadwaita and I want to use C++ plus CMake in order to do so.

While with pkg-config I am able to find libadwaita:

pkg-config --cflags libadwaita-1
-mfpmath=sse -msse -msse2 -pthread -I/usr/include/libadwaita-1 -I/usr/include/gtk-4.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
pkg-config --libs libadwaita-1
-ladwaita-1 -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

when using CMake and in particular CMake's PkgConfig (as explained in this answer) I am not able to find the library:

Here is what I tried

find_package(PkgConfig REQUIRED)

pkg_check_modules(libadwaita-1 REQUIRED IMPORTED_TARGET libadwaita-1)

but I get the following error:

-- Checking for module 'libadwaita-1'
--   Package 'libadwaita-1', required by 'virtual:world', not found
CMake Error at /app/extra/clion/bin/cmake/linux/share/cmake-3.23/Modules/FindPkgConfig.cmake:605 (message):
  A required package was not found
Call Stack (most recent call first):
  /app/extra/clion/bin/cmake/linux/share/cmake-3.23/Modules/FindPkgConfig.cmake:827 (_pkg_check_modules_internal)
  CMakeLists.txt:11 (pkg_check_modules)


-- Configuring incomplete, errors occurred!

EDIT: Since I'm using CLion as ide, after @Tsyvarev's comment I opened the CLion's terminal and run pkg-config:

sh-5.1$ pkg-config --cflags libadwaita-1
Package libadwaita-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libadwaita-1.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libadwaita-1', required by 'virtual:world', not found
sh-5.1$ 

I got the error above, so the problem is the one identified by Tsyvarev.

How do I set CLion so to never incur in such problems again? I need it to see all the libraries installed on my system.

0 Answers
Related