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(CMAKE_CXX_STANDARD 20)

project(hellogtkk)
set(SOURCE_FILES main.c)

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

include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})

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(CMAKE_C_STANDARD 99)

set(SOURCE_FILES main.c)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED gtk4)

include_directories(${GTK_INCLUDE_DIRS})
link_directories(${GTK_LIBRARY_DIRS})

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

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