Unable to compile code with GTK

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 06:31:03

问题


I want to learn to use GTK3 but I am not able to compile the first example.

I installed MSYS2 and ran:

pacman -S mingw-w64-x86_64-gtk3

followed by:

pacman -S mingw-w64-x86_64-glade

and:

pacman -S mingw-w64-x86_64-devhelp

I installed it at c:\MSYS64 which is the default location but when I try and run

gcc `pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0`

to compile the Simple Window tutorial

#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;
}

I get an error:

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.           

This is from command prompt so I thought of trying to use MSYS2 shell but I got an error saying -bash: gcc: command not found. I also tried moving the script to C:\msys64\home\ but that returns the same error.

Somewhere I have skipped something or am doing something wrong but I really cannot understand what. I have been trying for the past month (on and off) and would really appreciate any help.

I use MinGW on Windows if that helps.


回答1:


gcc: error: `pkg-config: No such file or directory

You're missing pkg-config. Please read all the GTK+ on Windows instructions. I wrote that page but can't guess wich language you're going to use. Step 5 there is needed if you chose C or C++, as you need basic build tools like pkg-config. I deliberately gave a command that pick lots of tools to avoid picking them one by one and someone missing a tool.

so please run:

pacman -S mingw-w64-x86_64-toolchain base-devel

Feedback welcome on how to improve the instructions page.



来源:https://stackoverflow.com/questions/46748779/unable-to-compile-code-with-gtk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!