title: Installing GTK for use in Code::Blocks on Windows 10
body: <h1>Original Question</h1>
  
  <p>I am having trouble installing gtk to start building GUIs in C++ on Code::Blocks. Could anyone nudge me in the right direction? I'm running Windows 10 (64-bit) on a Lenovo. </p>
  
  <p>I attempted an installation guide (<a href="https://www.youtube.com/watch?v=jvQXvTtSIQo" rel="nofollow noreferrer">https://www.youtube.com/watch?v=jvQXvTtSIQo</a>), stack overflow (<a href="https://stackoverflow.com/questions/32662215/how-do-you-install-gtk-3-0-on-windows">How do you install GTK+ 3.0 on Windows?</a>), the official GTK installation guide (<a href="https://www.gtk.org/download/windows.php" rel="nofollow noreferrer">https://www.gtk.org/download/windows.php</a>), a written guide (<a href="http://www.tarnyko.net/repo/gtk3_build_system/tutorial/gtk3_tutorial.htm" rel="nofollow noreferrer">http://www.tarnyko.net/repo/gtk3_build_system/tutorial/gtk3_tutorial.htm</a>), and just noticed a very similar stack overflow (<a href="https://stackoverflow.com/questions/37737020/install-gtk-for-c-on-windows-10">Install GTK for c on Windows 10?</a>) </p>
  
  <p>Before this, my PATH environment variable only recorded C:\Users\Owner\AppData\Local\Microsoft\WindowsApps;C:\Users\Owner\AppData\Roaming\npm;C:\Users\Owner\AppData\Local\atom\bin;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;</p>
  
  <p>I downloaded MinGW from mingw.org. This was to the youtube link's comment that the official is more stable than the one that can be installed with Code::Blocks. I added C:\MinGW\bin to PATH. </p>
  
  <p>Trying the official GTK installation site, I downloaded MSYS2 and used pacman -Syu to install core system packages and pacman -Su to then update. That's the end of that, so I think gtk is officially installed, I just need to get it to talk to Code::Blocks. I added C:\msys64\mingw64\bin to PATH but that didn't seem to work. </p>
  
  <p>I tried to install the all-in-one bundle for GTK 3.6.4 at <a href="http://www.tarnyko.net/dl/gtk.htm" rel="nofollow noreferrer">http://www.tarnyko.net/dl/gtk.htm</a> , and extracted it to C:\gtk. I now have C:\gtk\bin in PATH. GTK should be in my path in one form or the other. I can run gtk3-demo and gtk-demo-application from CMD but not MSYS2. I'm a bit confused about that. It probably has something to do with MSYS2's specific path variable, I think? But it should search the system's PATH afterward? And I don't know how to change that specific path? Probably questions for another day. </p>
  
  <p>So the similar stack overflow, youtube, and written tutorial all say to use <code>pkg-config --cflags --libs gtk+-3.0</code> to check for a reasonable output to see if I have gtk correctly installed. I installed 
  pkg-config-lite to avoid the glib circular dependency issue that <a href="https://stackoverflow.com/questions/1710922/how-to-install-pkg-config-in-windows">How to install pkg config in windows?</a> describes and frankly I do not understand. I added it to C:\MinGW\bin to by in my path. Now I am able to run it, but get:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I tried 3.6.4 instead of 3.0. No dice. I tried just 3. Nope. I can only find gtk3 files, and not the actual version I installed anywhere. pkg-config --cflags --libs says that I need to name a library, so I tried just gtk hopiing to get libraries containing that. Nope. The rest of the tutorials are aimed at getting Code::Blocks compiler (I think) to include gtk. I hope this is the only obstacle, and I will be able to get the rest. But, if anyone can help me through the rest, it would be appreciated. </p>
  
  <p>At this point I'm out of ideas. Can someone help me?</p>
  
  <p>Gratefully,
  John</p>
  
  <h1>More Questions After Liberforce's Answer</h1>
  
  <p>Thank you for writing up <a href="https://www.gtk.org/download/windows.php" rel="nofollow noreferrer">https://www.gtk.org/download/windows.php</a> !! I bet it helps a lot of frustrated newbies like myself. I will kindly offer more proper feedback after I get everything to work. I am stuck on compiling a C/C++ program, if you can help more. Before I get to that, I want to be very clear about the precise steps I took. The step names correspond to your written instructions. </p>
  
  <h2>Step 1: Install MSYS2</h2>
  
  <p>Alright, resetting everything...</p>
  
  <p>Removed C:/gtk directory from PATH and from computer, aka all the tarnyko files.</p>
  
  <p>Removed C:/MinGW directory from PATH and from computer, effectively uninstalling. I read your conversation with Simon (<a href="https://stackoverflow.com/questions/46748779/unable-to-compile-code-with-gtk">Unable to compile code with GTK</a> and <a href="https://chat.stackoverflow.com/rooms/156828/discussion-between-liberforce-and-simon">https://chat.stackoverflow.com/rooms/156828/discussion-between-liberforce-and-simon</a>) about the confusion between MinGW's terminal which includes msys1.0 and MSYS2 terminal which includes MinGW. I figured this would be safer. </p>
  
  <p>Thus, I only have C:\msys64 in PATH (and what I had before, irrelevant to GTK).  </p>
  
  <p>Uninstalled MSYS2 (via Add/Remove Programs) and reinstalled using the x86_64 from www.msys2.org. On pacman -Syu, I received error, "msys2-runtime and catgets are in conflict" and "msys2-runtime and libcatgets are in conflict." Entered y to remove both.</p>
  
  <p>I keep uninstalling and reinstallling but I hit the following problem... (5/5) upgrading pacman was at 100% and the warning pops up:
      warning: terminate MSYS2 without returning to shell and check for updates again
      warning: for example close your terminal window instead of calling exit</p>
  
  <p>The program halts here. I assume this means to close the window. I did, and clicked OK for the dialogue "Processes are running in session: Close anyway?." Window now printed "Hangup signal received" and it is no longer responding. I use task-manager to kill it. </p>
  
  <p>Openning MSYS2 by the desktop application after the first pacman -Syu gave me the dialogue to choose which shell: MSYS2, Mingw-w64 32 bit, Mingw-w64 64 bit. I instead went into the filesystem and openned C:\msys64\msys2_shell.cmd for all future instances.</p>
  
  <p>Ran pacman -Syu to finish installing packages. I restart MSYS2 again, and ran pacman -Su to reveal </p>
  
  <pre><code>:: Starting core system upgrade...
   there is nothing to do
  :: Starting full system upgrade...
   there is nothing to do
  </code></pre>
  
  <p>pacman -Syuu showed:</p>
  
  <pre><code>:: Synchronizing package databases...
   mingw32 is up to date
   mingw64 is up to date
   msys is up to date
  </code></pre>
  
  <p>The pacman -Su, pacman -Sy, and pacman -Suu likewise reveal everything okay. Closed and reopenned C:\msys64\msys2_shell.cmd</p>
  
  <p>pkg-cofig just gives "bash: pkg-config: command not found." So I ran pacman -S pkg-config and got that working. update-core, though, which is mentioned in <a href="https://github.com/msys2/msys2/wiki/MSYS2-installation" rel="nofollow noreferrer">https://github.com/msys2/msys2/wiki/MSYS2-installation</a> cannot be found, and pacman -S update-core will not work. pacman -Ss core turns up: </p>
  
  <pre><code>msys/coreutils 8.26-2 (base) [installed]
  The basic file, shell and text manipulation utilities of the GNU operating
  system
  </code></pre>
  
  <p>And other files that seem unrelated. Results of pacman -Ss core likewise seem irrelevant. </p>
  
  <p>pacman --version shows:</p>
  
  <pre><code> .--.                  Pacman v5.0.1 - libalpm v10.0.1
  / _.-' .-.  .-.  .-.   Copyright (C) 2006-2016 Pacman Development Team
  \  '-. '-'  '-'  '-'   Copyright (C) 2002-2006 Judd Vinet
   '--'
                         This program may be freely redistributed under
                         the terms of the GNU General Public License.
  </code></pre>
  
  <p>Ran "pacman --needed -S bash pacman pacman-mirrors msys2-runtime" to reveal:</p>
  
  <pre><code>warning: bash-4.4.019-2 is up to date -- skipping
  warning: pacman-5.0.1-5 is up to date -- skipping
  warning: pacman-mirrors-20160112-1 is up to date -- skipping
  warning: msys2-runtime-2.10.0-2 is up to date -- skipping
   there is nothing to do
  </code></pre>
  
  <p>I exited out of all msys shells, and ran C:\msys64\autorebase.bat, although not on a 32 bit system. I believe there is a typo when it says to reopen msys2_shell.bat, which I do not have. I openned msys2_shell.cmd. I use pacman -Suu once more to reveal that everything is okay. </p>
  
  <h2>Step 2 -> Step 5 (optional): Install build tools</h2>
  
  <p>Openned C:\msys64\msys2_shell.cmd and ran "pacman -S mingw-w64-x86_64-gtk3" (GTK+3 package) and "pacman -S mingw-w64-x86_64-toolchain base-devel" (package to develop GTK+3 applications in other languages) (defaulted to all installations when prompted). </p>
  
  <h2>Failed to Compile a GTK+3 Application</h2>
  
  <p>Restarted computer. Openned C:\msys64\msys2_shell.cmd. Following <a href="https://developer.gnome.org/gtk3/stable/gtk-getting-started.html" rel="nofollow noreferrer">https://developer.gnome.org/gtk3/stable/gtk-getting-started.html</a>.</p>
  
  <p>Put the simple window tutorial file in C:\Users\Owner\Desktop\test_code\example-0.c . When running gcc pkg-config --cflags gtk+-3.0 -o example-0 example-0.c pkg-config --libs gtk+-3.0 , got the error in my original question. Used "pacman -Ss gtk3" to see two packages I think I need. Ran "pacman -S mingw-w64-x86_64-gtk3 mingw-w64-x86_64-gtkmm3" .</p>
  
  <p>To answer your questions to Simon about this same error at <a href="https://stackoverflow.com/questions/46748779/unable-to-compile-code-with-gtk">Unable to compile code with GTK</a> ,  <code>pkg-config --list-all | grep gtk</code> returns nothing, even after closing and reopenning C:\msys64\msys2_shell.cmd. "which gcc" returns:</p>
  
  <p>which: no gcc
  in(/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:
  /c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:
  /usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)</p>
  
  <p>I see gtk-3.0 under C:\msys64\mingw64\include. I have no idea how to add this to the path. "echo $PKG_CONFIG_PATH" returns:</p>
  
  <pre><code>/usr/lib/pkgconfig:/usr/share/pkgconfig:/lib/pkgconfig
  </code></pre>
  
  <h1>Correctly Compiled a File in Console with GTK+3</h1>
  
  <h2>Checked that GTK was in Console</h2>
  
  <p>I needed to open up MSYS2 in a Mingw-w64 64 bit shell. This can be preformed via the Desktop app for MSYS2 which prompts you which one of three shells you want to open: MSYS2, Mingw32, and Mingw64. Specifically, me installing gtk with the command <code>mingw-w64-x86_64-toolchain</code> means it can only be accessed this way. </p>
  
  <p>Commands in this shell show that I do, in fact, have gtk:</p>
  
  <p><code>$ pkg-config --modversion gtk+-3.0</code> --> <code>3.22.29</code> </p>
  
  <p><code>$ which gcc</code> --> <code>/mingw64/bin/gcc</code></p>
  
  <h2>Compiled Sample Code from Mingw64 Console</h2>
  
  <p>I referenced <a href="https://github.com/msys2/msys2/wiki/MSYS2-introduction" rel="nofollow noreferrer">https://github.com/msys2/msys2/wiki/MSYS2-introduction</a> to learn the file system / drive mounting syntax. I will place the sample code gotten from <a href="https://developer.gnome.org/gtk3/stable/gtk-getting-started.html" rel="nofollow noreferrer">https://developer.gnome.org/gtk3/stable/gtk-getting-started.html</a> in `/c/Users/Owner/Desktop/test_code/example-0.c'. I just used my favorite IDE, Atom, but any text editor would do. </p>
  
  <p>Openned MSYS2's Mingw64 shell, cd <code>/c/Users/Owner/Desktop/test_code/</code> , compiled with <code>gcc \</code>pkg-config --cflags gtk+-3.0` -o example-0 example-0.c `pkg-config --libs gtk+-3.0`` , and execute with <code>./example-0</code></p>
  
  <h1>Unsuccessful to Link GTK+3 and the Code::Blocks Compiler</h1>
  
  <h2>I Understand some Linker Settings</h2>
  
  <p>I went into Code::Blocks. Went to Settings > Compiler... Made sure to use the dropdown box under Selected compiler to select GNU GCC Compiler, and clicked Reset Defaults because of complications when I first installed Code::Blocks. The check boxes under Compiler Flags should all blank after the reset, and so I checked "Have g++ follow the C++14 ISO C++ language standard [-std=c++14]" under General and "Enable all common compiler warnings (overrides many other settings) [-Wall]" under Warnings. </p>
  
  <p>Next to where it says Compiler Flags, I went to Linker settings and added text to Other linker options. I got this text by running <code>pkg-config --cflags gtk+-3.0</code>:</p>
  
  <pre><code>-mms-bitfields -pthread -mms-bitfields -IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include/fribidi -IC:/msys64/mingw64/include/atk-1.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -LC:/msys64/mingw64/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lz -lpangowin32-1.0 -lpangocairo-1.0 -lpango-1.0 -lfribidi -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
  </code></pre>
  
  <p>Explanation: When compiling from console, I used a command that included the text <code>/</code>pkg-config --cflags gtk+-3.0`` . The backticks mean to run <code>pkg-config --cflags gtk+-3.0</code> BEFORE the higher-level compilation command, and insert whatever text comes out into the higher-level compilation command. Code::Blocks needs that text under the Linker settings.</p>
  
  <h2>I do not Understand the Search Directories</h2>
  
  <p>In Settings > Compiler... , beside where it says Compiler Settings, I clicked Search directories. I know you need to do some work here. After this, you go back to Linker Settings to finish, and your Code::Blocks will be ready to go!</p>
  
  <p>If anyone can help me here, or if I figure it out, I would love to finish, in case this helps posterity. I have GTK compiling, and that is good enough for now. </p>