osm-gsm-map on Windows with GTK+

Categories How to, Programing

This year at school, we have a C language project to do in team, and the subject was totally free. So we had the idea to make an application that tracks Solex in real time for the Rock’n Solex fest, in order to allow people to see the position, lap-times and speed of the runners at any instant.

As we are obligated to do it in C language, we chose to use GTK+ library for our client interface, that will show a map with one marker for each runner. After some research on the web, we found osm-gps-map, a sort of widget for GTK+ that allows fetching maps from OpenStreetMap project.

The purpose of this post is to explain how to properly install and use GTK+ under Windows, and how to make the C example file provided by the official website working. The IDE that will be used is Code::Blocks.

The explaination below might be very complex for beginners. You have to follow rigorously the steps I give. Normally, this example respect the universality of paths for the project, that allows export easly your sources on a SVN to work in team for example.


  • Code::Blocks 12.11 IDE installed on the computer.
  • GTK+ 3.6.1 for Windows
  • osm-gps-map sources
  • libsoup-2.26 library
  • a LOT of patience

Part 1 : Installing the right version of GTK+

First of all, I tried to compile the C example file with an old version of GTK+ (2.21). It didn’t work at all because the code contains reference to structures (like GDKRgba) and function only available in GTK above 3.0. Curiously, it’s quite hard to find pre-compiled version of GTK+ for Windows. By luck, a french guy (cock a doodle doo!) called Tarnyko compiled the latest version GTK+ binaries for Windows.

1.) Download GTK+-Bundle-3.6.1_(TARNYKO).exe on this page. This bundle contains 2 importants part : the first one contains the runtime DLLs, that allows you to execute any application that requires GTK to run (Pidgin for example), and the second part is a bunch of .c, .h, .dll, and .a files. Theses files are needed for developing GTK applications.

2.) Install the package in C:\GTK3 for example. This is how your GTK folder should look like:


3.) We will create a new GTK+ project in Code::Blocks. First, we have to hack the Code::Blocks GTK+ wizard’s script to allow creating GTK version 3+ project. Indeed, the name of the GTK include folder has changed between v. 2.x and 3.x : it’s gtk-3.0 instead of gtk-2.0, as well as the name of the gtk-win32-2.0 lib in gtk-win32-3.0. We need to update the Code::Blocks script!

  •  Go in “C:\Program Files\CodeBlocks\share\CodeBlocks\templates\wizard\gtk”
  •  Edit (with admin right) the wizard.script file.
  • Look for these lines:

line 57 : if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))

line 64 : if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-2.0"), _T("GTK's")))

line 116 : project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));

line 123 : project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0")  + wxFILE_SEP_PATH + _T("include"));

line 131 : project.AddLinkLib(_T("gtk-win32-2.0"));

and change them like that:

if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-3.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))

if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-3.0"), _T("GTK's")))

project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-3.0"));

project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-3.0")  + wxFILE_SEP_PATH + _T("include"));


Now, codeblocks should create your project with the right paths for includes and libraries.

4.) Start CB12.11 (Code::Blocks) and create a new GTK+ project.

5.) Give a name to your project


6.) Create a new Windows environnement variable, in order to avoid hard-coded path in your .cpb file. This step is HIGHLY RECOMMENDED. It will avoid you having some .dll error when launching your future application, and it is more flexible when you work in team on SVN for example.



7.) Try to compile your project. If you have an error, check the name of each used files in the .cpb file, the file of your Code::Blocks project (you can open it with a text editor).

Now, we are able to code and compile application with GTK3 using Code::Blocks IDE. I will now show you how to use the osm-gps-map widget.

Part 2 : using osm-gps-map widget

8.) Download the latest osm-gps-map sources here. DON’T DOWNLOAD SOURCES FOR WINDOWS as indicated on the project homepage! They are totally outdated. Extract the archive in a folder on your Desktop.

9.) Create a new folder in C:\GTK3\include called osmgpsmap.

10.) Copy all header files (.h) in this folder


11.) You need to add this new created folder to your include directory in CB. It indicates to your compiler where the header files are located. Go to Project->Build Options->Search Directories, Compiler tab, and add the path: $(#gtk)\include\osmgpsmap. See Step 13 for a screenshot.

12.) In the  Compiler Settings tab of the Project build options window, click on the sub-tab “Other options” and add pkg-config --cflags gtk+-3.0. Then go to “Linker settings” tab and add pkg-config --libs gtk+-3.0 in “Other linker options”. Be careful of comma, is different of `.



13.) Now, we have to install the libsoup module for GTK, that is required to compile the osm-gps-map widget:

  • Download the dev package for Windows here. Download the libsoup-dev_2.26.3-1_win32.zip file.
  • Extract the include and the lib folder in your GTK folder (C:\GTK3)
  • Add the directory  $(#gtk)\include\libsoup-2.4 to the compiler search path, as explained at step 11.


14.) It’s time to add all the libraries to the linker! Always in the “Linker settings” tab, add all .lib contained in your C:\GTK3\lib, as well as the libsoup-2.4.dll.a. If asked, keep relative path.


15.) Then copy all .c files in your project folder (i.e where your .cpb file is), and add them all to your project.


16.) Copy the content of the mapviewer.c in your main.c.  This file is located in the example folder of the osm-gps-map archive you downloaded.

17.) Now, the include folder should be found by Code::Blocks when compiling. So you can change the #include “osm-gps-map.h” of your main.c by #include <osm-gps-map.h>.

18.) Edit the osm-gps-map-widget.c and remove the #include “config.h” line. I don’t know the role of this file and it make the compilation fail.

19.) Try to compile now! It should not failed this time. Please read the next part to know how to launch your application.

Part 3 : Launching your application

Ok, you have right-compiled your porject after a hour of sweating on your keyboard. We have to resolve some .dll dependencies errors.

19.) We have to get the binary .dll of the libsoup library. Go back on this webpage and download libsoup_2.26.3-1_win32.zip . Then, copy the libsoup-2.4-1.dll contained in the archive next to your executable (“.exe”), generally located in /bin/Debug in your project folder.

20.) Finally, copy the mapviewer.ui and the poi.png files next to your “.exe” file.


21.) Try to launch your application. It should work!



As you can see, some libraries are very hard to install, especially when they are not compiled and they had a lot of dependencies. I guess that the tough point is to find and to memorize the procedure to be able to do it again. Having good knowledge concerning how an entire program is translated from line code to a series of bits is very important as well.

I'm passionnated

Leave a Reply

Your email address will not be published. Required fields are marked *