Help with a CMakeLists.txt for GTK 4

I’m getting started learning GTK and I’m using CLion as an IDE.

I was able to track down a CMakeList.txt file to use with the IDE that seems to tell it how to find GTK 3 and a cut simple HelloWorld app cut and paste from GTK 3 docs builds and runs in the IDE with no problems.

I then tried the HelloWorld example for GTK4 and that throws an error and I’m not sure what to change in the CMakeLists.txt to make it pick up the GTK4 libraries.

I’ve hunted high and low and can’t find any example CMakeList.txt examples that work with GTK 4.

The GTK 3 example that works fine is:

cmake_minimum_required(VERSION 3.17)


set(SOURCE_FILES main.c)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)


add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${GTKMM_LIBRARIES})

And what would that error be?

ok so I figured it out and basically I had the wrong name for the GTK dependency.

I should have put

cmake_minimum_required(VERSION 3.20)
project(Hello C)


set(SOURCE_FILES main.c)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED gtk4)


add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${GTK_LIBRARIES})

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.