glibmm.h: 找不到这样的目录或文件

glibmm.h: could not find such directory or file

我想将 gtk 包含到我的新 cmake 项目中。但是当我编译时,我得到了这个错误:+

In file included from /home/chhu/CLionProjects/MasterMind/main.cpp:2:
/usr/include/gtkmm-3.0/gtkmm.h:87: fatal error: glibmm.h: could not find such directory or file

这是我的 cmake 文件:

cmake_minimum_required(VERSION 3.17)
project(MasterMind)
set(CMAKE_CXX_STANDARD 14)

# Use the package PkgConfig to detect GTK+ headers/library files
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)

# Setup CMake to use GTK+, tell the compiler where to look for headers
# and to the linker where to look for libraries
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})

# Add other flags to the compiler
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})

add_executable(MasterMind main.cpp)

# Link the target to the GTK+ libraries
TARGET_LINK_LIBRARIES(MasterMind ${GTK3_LIBRARIES})

这是我的 class:

#include <gtkmm-3.0/gtkmm.h>

int main(int argc, char *argv[]) {
auto app =
        Gtk::Application::create(argc, argv,
                                 "org.gtkmm.examples.base");

Gtk::Window window;
window.set_default_size(200, 200);

return app->run(window);
}

我正在 ubuntu 20.4 下开发。我的 g++ 版本是 9.3.0.

Gtkmm 不是 Gtk 的一部分。你应该更新你的 CMakeLists

PKG_CHECK_MODULES(GTKMM3 REQUIRED gtkmm-3.0)
INCLUDE_DIRECTORIES(${GTKMM3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTKMM3_LIBRARY_DIRS})

ADD_DEFINITIONS(${GTKMM3_CFLAGS_OTHER})

TARGET_LINK_LIBRARIES(MasterMind ${GTKMM3_LIBRARIES})