Search code examples
cgtkgtk3msys2

Install GTK for c on Windows 10?


Can you tell me how to install GTK on windows 10 or have a step by step guide, all the ones I've tried have not helped me. Possibly if someone also explain how to compile from cmd or prepare an IDE (code: block maybe).


Solution

  • Any commands I mention should be run at the MINGW shell, found here: C:\msys64\msys2_shell.cmd

    First update msys2 with pacman -Syu

    Make sure you have installed GCC...Install the required toolchain for GCC with pacman -S mingw-w64-x86_64-toolchain. When using pacman, just keep typing enter if prompted to follow through with the installation and get back to the command prompt.

    In order to set this step up with Code:Blocks, make sure you go to the Code:Blocks menu Settings->Compiler, and the menu Toolchain Executables. From there, put in the msys2 installation directory and where you installed MinGW's GCC compiler (for me this was putting C:\msys64\mingw64) under the compiler's installation directory option. Also edit the C Compiler path under the same menu to x86_64-w64-mingw32-gcc.exe.

    Next, in order to install gtk+3.0, use the command pacman -S mingw-w64-x86_64-gtk3. Now the latest version of GTK+3.0 will have been installed, so it is time to set it up with Code:Blocks.

    Open Code:Blocks and create a new C file. You may definitely write your code in Code:Blocks, but I do not suggest that you compile it from there. Two compile, go back to the MINGW shell. Type nano ~/.bashrc to edit it. You may scroll down using the arrow keys to the bottom of the file and add: PATH=$PATH:/c/msys64/mingw64/bin. Restart the MINGW shell and open it back up.

    Finally, try running:

    gcc source.c -o executable.exe `pkg-config --cflags --libs gtk+-3.0`.
    

    If that command doesn't work, I would suggest using the i686 version of gcc installed in MINGW.

    I hope this helps!