я написал эту программу в C на моем win10 p c, используя Clion 2019.2.4.
#include <stdio.h>
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
printf("Hello, World!\n");
gtk_init(&argc, &argv);
GtkWindow *window;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
gtk_main();
return 0;
}
Это мой CmakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(gtk_test C)
set(CMAKE_C_STANDARD 99)
# Use the package PkgConfig to detect GTK+ headers/library files
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTK 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(${GTK_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK_LIBRARY_DIRS})
# Add other flags to the compiler
ADD_DEFINITIONS(${GTK_CFLAGS_OTHER} )
# Add an executable compiled from hello.c
add_executable(gtk_test main.c)
# Link the target to the GTK+ libraries
TARGET_LINK_LIBRARIES(gtk_test ${GTK_LIBRARIES})
Но когда я пытаюсь запустить его ...:
Hello, World!
Unable to init server: Could not connect to 127.0.0.1: Connection refused
(gtk_test:2342): Gtk-WARNING **: cannot open display: export DISPLAY=localhost:0.0
Process finished with exit code 1
Код: https://i.stack.imgur.com/XQf7H.jpg
Я использую Cygwin: https://i.stack.imgur.com/rN8z2.jpg