Include Library into C++ Project using Cmake

59 Views Asked by At

I want to use gtkmm-4.0 in a C++ project. I installed it using msys. Now the gtmm-4.0.h file is saved at "C:\msys64\mingw64\include\gtkmm-4.0". And i have the following CMakeLists.txt file.

cmake_minimum_required(VERSION 3.26)
project(Testing)

include_directories("C:/msys64/mingw64/include/gtkmm-4.0")
link_directories("C:/msys64/mingw64/lib/gtkmm-4.0")

add_executable(main main.cpp)

target_link_libraries(main gtkmm-4.0.lib)

But this doesn't work because the gtkmm-4.0 library also relies on glibmm and giomm. These are also saved in the mingw64-folder. But if i link them both seperately, there is always something that does not get linked. Which means how i'm doing it is wrong. I basically need to include everything in mingw64. But i don't know how to do that. I tried with

cmake_minimum_required(VERSION 3.26)
project(Testing)

include_directories("C:/msys64/mingw64/include")
link_directories("C:/msys64/mingw64/lib")

add_executable(main main.cpp)

target_link_libraries(main mingw64.lib)

But this also didn't work. So how do i include the whole library?

1

There are 1 best solutions below

2
Botje On

Instead of chasing dependencies yourself, get this information from the supplied pkg-config files:

find_package(PkgConfig REQUIRED)
pkg_check_modules(Gtkmm REQUIRED IMPORTED_TARGET gtkmm-4.0)
target_link_libraries(main PUBLIC PkgConfig::Gtkmm)