c - 无法使用 GTK 编译代码

标签 c gtk mingw

我想学习使用 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/

相关文章:

c++ - 使用 MinGW windows 7 将静态库 .lib 转换为动态库 .dll

c - 使用指针获取数据并在C中的另一个函数中使用它们

c++ - 在跨平台 Gtk 应用程序中嵌入 Web 浏览器

python gtk多窗口

c++ - 特殊字符 C/C++

python - Windows XP : "error: Unable to find vcvarsall.bat" 中的 Cython 问题

在 vb.net 中调用 winAPI 函数

c - 迭代文件时如何通过元素索引循环而不是逐个字符进行迭代

python - PyGObject GTK+ 3 - 文档?

c++ - 如何在C++中定义常量?