我想学习使用 GTK3,但我无法编译第一个示例。
我安装了 MSYS2
然后跑:
pacman -S mingw-w64-x86_64-gtk3
其次是:
pacman -S mingw-w64-x86_64-glade
和:
pacman -S mingw-w64-x86_64-devhelp
我将它安装在默认位置 c:\MSYS64
但当我尝试运行时
gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0`
编译Simple Window教程
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_widget_show_all (window);
}
int main (int argc, char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
我得到一个错误:
C:\Users\Simon\Desktop\webbrowser>gcc `pkg-config --cflags gtk+-3.0` -o example-1 example-1.c `pkg-config --libs gtk+-3.0`
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: example-1.c: No such file or directory
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: unrecognized command line option '--cflags'
gcc: error: unrecognized command line option '--libs'
gcc: fatal error: no input files
compilation terminated.
这是来自命令提示符,所以我想尝试使用 MSYS2 shell,但我收到一条错误消息:-bash: gcc: command not found
。我还尝试将脚本移动到 C:\msys64\home\
但返回相同的错误。
我在某处跳过了某些内容或做错了什么,但我真的不明白是什么。过去一个月我一直在尝试(断断续续),非常感谢任何帮助。
如果有帮助,我会在 Windows 上使用 MinGW。
最佳答案
gcc: error: `pkg-config: No such file or directory
您缺少 pkg-config
。请阅读全部 GTK+ on Windows指示。我写了那个页面,但无法猜测您将使用哪种语言。如果您选择 C 或 C++,则需要第 5 步,因为您需要像 pkg-config
这样的基本构建工具。我特意下了一个命令,选择很多工具,以避免一个一个地挑选,而有人缺少一个工具。
所以请运行:
pacman -S mingw-w64-x86_64-toolchain base-devel
欢迎就如何改进说明页面提供反馈。
关于c - 无法使用 GTK 编译代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46748779/