1

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.

liberforce
  • 11,189
  • 37
  • 48
Xantium
  • 11,201
  • 10
  • 62
  • 89

1 Answers1

3
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.

liberforce
  • 11,189
  • 37
  • 48
  • Thanks I did that and `pgk-config` can now be found in Msys shell however I get another error: `Package gtk+-3.0 was not found in the pkg-config search path. Perhaps you should add the directory containing gtk+-3.0.pc' to the PKG_CONFIG_PATH environment variable No package 'gtk+-3.0' found Package gtk+-3.0 was not found in the pkg-config search path. Perhaps you should add the directory containing gtk+-3.0.pc' to the PKG_CONFIG_PATH environment variable No package 'gtk+-3.0' found bash: gcc: command not found ` What do I do do now? – Xantium Oct 16 '17 at 11:20
  • Oh I want to use C by the way. – Xantium Oct 16 '17 at 11:48
  • What does `pkg-config --list-all | grep gtk` returns? – liberforce Oct 16 '17 at 12:05
  • And `which gcc`? – liberforce Oct 16 '17 at 12:08
  • `pkg-config --list-all | grep gtk` returns `gtk+-3.0 GTK+ - GTK+ Graphical UI Library gtk+-win32-2.0 GTK+ - GTK+ Graphical UI Library (win32 target) javascriptcoregtk-3.0 JavaScriptCoreGTK+ - GTK+ version of the JavaScriptCore engine webkitgtk-3.0 WebKit - Web content engine for GTK+ gtk+-broadway-3.0 GTK+ - GTK+ Graphical UI Library gtk+-win32-3.0 GTK+ - GTK+ Graphical UI Library gtk+-2.0 GTK+ - GTK+ Graphical UI Library (win32 target)` and I am using the Msys gcc because I removed MinGW from path. – Xantium Oct 16 '17 at 12:12
  • Thanks for the pkg-config result. However, for my second question, I was asking about the value returned by the command line tool named `which`. So please run the `which gcc` command in your MSYS2 terminal. – liberforce Oct 16 '17 at 12:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156828/discussion-between-liberforce-and-simon). – liberforce Oct 16 '17 at 12:15
  • @liberforce I am interested in this discussion because pkg-config can't seem to find my packages. C:\WINDOWS\system32>pkg-config --list-all libalpm libalpm - Arch Linux package management library bash-completion bash-completion - programmable completion for the bash shell libmakepkg libmakepkg - Arch Linux package build utility C:\WINDOWS\system32>pkg-config --list-all | grep gtk C:\WINDOWS\system32> As you can see, gtk, glade, etc., are not listed. I followed your tutorial, and added other libraries. Any ideas what I might have done wrong? – Jillinger Mar 09 '20 at 03:10
  • If the behavior is different, it's better to ask your own question referencing this one. – liberforce Mar 09 '20 at 09:43
  • I got it sorted out. I just needed to point the PKG_CONFIG_PATH to C:\msys64\mingw64\lib\pkgconfig. – Jillinger Mar 09 '20 at 17:43
  • If you have to set that with MSYS, it's probably that you're running the wrong shell at startup. AFAIR, there are two shortcuts created at install time, with some configuration differences. Try the other one, because usign the wrong shell could lead to other errors later down the line. You shouldn't have to set PKG_CONFIG_PATH by yourself, this is configured by default. – liberforce Mar 10 '20 at 09:08
  • I was wondering about that, but since this tutorial - https://www.gtk.org/docs/installations/windows/ - directed using the MSYS2 shell, I figured it was what I should use. Do you think I should run the Mingw-w64 64bit shell? I don't know... The instructions are specifically for Windows, so I have no other official instructions to follow. – Jillinger Mar 10 '20 at 10:45
  • Yeah, the MSYS2 shell is a vanilla shell. Mingw is Minimal GNU for Windows, and is generally used to have a configured gcc for Windows. Using that shell, you shoul have everything preconfigured to compile a C program. – liberforce Mar 10 '20 at 11:26
  • That install page tells to use the MSYS2 shell but that's for package installation. I wrote that a while back, not seing the different shells provided (or thinking people would figure it out), so I didn't see the problem. – liberforce Mar 10 '20 at 11:28
  • If you are suggesting I should use the Mingw-w64 64bit shell, just let me know if that would work better for me. I don't know. I can't figure everything out, since I don't know about everything... especially programs written by other people. I usually like to follow manuals provided by those who know what they made, as they would know better... or should. I think I should learn from those who know... if I don't know. In this case, I don't. Should I run the Mingw-w64 64bit shell? – Jillinger Mar 10 '20 at 13:05
  • Yes, use the Mingw-w64 64bit shell and run the very same pkg-config commands, it should work. – liberforce Mar 10 '20 at 14:08
  • Okey Dokey. Thanks. – Jillinger Mar 10 '20 at 20:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/209423/discussion-between-jillinger-and-liberforce). – Jillinger Mar 11 '20 at 07:55