Cross-platform Windows / Raspberry Pi project with C++, OpenCV and Gtk
Last Updated :
07 Apr, 2025
Introduction
This article belongs to a series of articles about writing, building and debugging an application written in C++, that uses Gtk library to handle the user interface, OpenCV library to capture and process images from the camera, compatible with the main platforms, Mac OS X, Linux and Windows, and ultimately running on Raspberry Pi.
The main article in the series is here:
- This article discusses how to configure your Windows to retrieve sources, build and debug such a project. The sources of the project are available here:
Install M2SYS
Windows doesn’t have standard system locations for libraries as Linux and Mac OS X have. In consequence, to obtain the Gtk and OpenCV libraries, you need to use some non-standard procedure that involves installing a special package manager called pacman and a special Linux-like development environment called MinGW.
The easiest way to obtain pacman and MinGW is through an open source project called MSYS2. Go to MSYS2 homepage and download the M2SYS installer that best corresponds to your system (probably the 64 one, as the i686 is actually 32 bits).
Install it with all default options, in C:\msys64
folder.
After installation you’ll have:
- The MSYS2 MSYS environment, where you can use pacman to install components.
- The MSYS2 MinGW 64-bit environment, which stands for Minimal GNU for Windows, and where you can use all tools and libraries installed via pacman.
- You also get the MSYS2 MinGW32, to access 32 bit tools; you shouldn’t install any of those if your system is 64 bits.

As explained in the download instructions, the first thing to do is to upgrade the package database. Open the MSYS2 MSYS and type the following command:
$ pacman -Syuu
Should you encounter the message below, close the MSYS2 MSYS window with your mouse, open it again, and run the same command, until it terminates normally.
warning: terminate MSYS2 without returning to shell and check for updates again
warning: for example close your terminal window instead of calling exit
If you’re looking for a particular package, you can use a command similar to the following. Assuming you look for CMake:
$ pacman -Ss cmake
Build a great linux-like toolkit
Inspired by Alexey Pavlov’s gist, I advise to install the following packages and tools so you have a development environment very similar to the one present in Linux machines. With it you can compile applications for windows using Linux tools:
$ pacman -S base base-devel net-utils git ruby wget man
$ pacman -S msys/openssh msys/vim msys/bc nano msys/tmux
$ pacman -S gzip zip unzip msys/p7zip tar msys/tree
$ pacman -S msys/winpty msys/ed msys/pwgen msys/zsh
$ pacman -S mingw64/mingw-w64-x86_64-jq
$ pacman -S msys/screenfetch
$ pacman -S mingw-w64-x86_64-toolchain
$ pacman -S mingw64/mingw-w64-x86_64-cmake
After downloading and installing all those packages, you can verify if they’re present testing some. To do this, open the MSYS2 MingGW 64 bit environment, and test some commands:
$ git --version
$ make --version
$ cmake --version
$ gcc --version
$ pkg-config --version
Installing Gtk and OpenCV
You can install the Gtk and OpenCV libraries using pacman in MSYS2 MSYS, with the following commands:
$ pacman -S mingw64/mingw-w64-x86_64-gtkmm3
$ pacman -S mingw64/mingw-w64-x86_64-opencv
Building with MinGW64
To build the project, open the MSYS2 MinGW 64-bit, locate an appropriate folder (the drive units are mapped to the root folder, for example C:\Users\me\Document\Development\
would be /c/Users/me/Development
):
$ cd navigate/to/your/project/folder
$ git clone https://github.com/cpp-tutorial/raspberry-cpp-gtk-opencv.git
$ cd raspberry-cpp-gtk-opencv
$ mkdir build
$ cd build
$ cmake -G"Unix Makefiles" ../src/
$ make
$ ./racapp.exe
If you want to debug with gdb, you can use slightly different cmake
command. If you already built the project, do not hesitate in deleting the build
folder and creating it again:
$ cd ..
$ rm -rf build
$ mkdir build
$ cd build
$ cmake -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ../src
$ make
$ gdb ./rascapp.exe
After that you’re in gdb. To find your way, look in Linux instructions.
Making MinGW tools available everywhere
By default, MSYS2 installs libraries and tools in the C:\Msys2\MinGW64\bin
folder. Add it to the PATH
environment variable, so that all applications can find the tools:

Once you’re done, you can open the Windows command line, and verify if the same tools are available from it:
$ pkg-config --version
$ pkg-config gtkmm-3.0 --cflags --libs
$ pkg-config opencv-3.0 --cflags --libs
This step is not strictly necessary if you’re going to use Code::Blocks, but it doesn’t hurt either.
Installing Code::Blocks in Windows and configuring MSYS2 toolchain
The default IDE in Windows is Visual Studio. However, Visual Studio expects a special format for debugging symbols that is not the one produced by gcc and g++ in MinGW. In a cross platform project, if you don’t want to make your life miserable following hyper complex installation procedures, is better to leave it out.
I chose Code::Blocks because:
- It exists in all three major platforms, so you can use it everywhere, including Raspberry Pi, with similar configuration.
- It’s pretty popular, so you can look for instructions and community support.
- It has a Windows installation wizard that takes cares of all configuration details.
The installation procedure is completely straight forward, at least in Windows 10
- Install a Windows binary release of Code::Blocks from official site: http://www.codeblocks.org/downloads.
- Among all versions, chose the normal setup (you already installed the mingw toolchain in the previous step).
- Install it with all default options.
- Launch application
If there are no error messages, you’re done. Otherwise, look at the troubleshooting.
Building with Code::Blocks
The easiest path is to use CMake to prepare a Code::Blocks project for you. Assuming that you already cloned the project in a known location, and your MSYS2 MinGW 64-bits terminal is already there, this is the sequence of commands:
$ mkdir codeb
$ cd codeb
$ cmake -DCMAKE_BUILD_TYPE=Debug -G"CodeBlocks - Unix Makefiles" ../src/
Follow the rest of the procedure from Code::Blocks:
- From the menu, File → Open…, look for the
codeb
folder that you just created, and for the rascam.cbp
project file in it (note that the name of the project is the same as specified in CMakeLists.txt
).
- If you like, go to Project → Project Tree and modify Display folders as on disk and Hide folder name.
- Select one of the source files and place a break point on it by clicking in the gray area.
- In the toolbar, select the
rascapp
target.
- In the toolbar, launch the debugger.
- It should launch, and stop at the breakpoint.
- To see the variables, go to Debug → Debugging windows → Watches.

Troubleshooting
invalid or corrupted package (PGP signature)
Occasionally you may found the following error message when downloading, updating or upgrading with pacman:
(4/4) checking package integrity [###################################################################] 100%
error: jsoncpp: signature from "Alexey Pavlov (Alexpux) "
is invalid
:: File /var/cache/pacman/pkg/jsoncpp-1.8.4-1-any.pkg.tar.xz is
corrupted (invalid or corrupted package (PGP signature)).
It is a transitory problem related with authoring websites being unavailable, and you can solve it by just waiting (see a discussion about signature problems from “Alexey Pavlov (Alexpux)”). Alternatively, you can deactivate the signature checking by editing /etc/pacman.conf
(use Vim from MinGW64) and changing the following entry:
SigLevel = Never
Code::Blocks cannot find the compiler
At launching, Code::Blocks may complain that it doesn’t find the compiler toolchain. If you have installed it with MSYS2 as described above, it is just a matter of configuration:
- At launching, just accept the dialog requiring you to choose an existing toolchain.
- In the main menu, open Settings → Compiler…
- In the dialog, look for Global compiler settings section, and Toolchain executables tab.
- Ensure that the path is correct. If you installed MSYS2 with default options, it should be
C:\msys64\mingw64
.
- Also ensure that all mentioned program files correspond to existing executables in that folder.
- Accept everything, and do the same with Settings → Debugger…

Note: I had this problem when I installed Code::Blocks with mingw-setup. I guess it expects a standard MinGW installation, and not the MSYS2 one.
Code::Blocks cannot save configuration
When closing the application, or when saving all data, Code::Blocks may complain that it cannot save configuration, and display an error message. To solve this:
- Take note of the path where it tries to save the configuration file.
- Create the same path, and an empty file with the same name.
- Make this file writable.
Note: I had this problem when I installed Code::Blocks with mingw-setup. I guess it expects a standard MinGW installation, and not the MSYS2 one.
Similar Reads
Can I Mix C and C++ Code in the Same Project?
C and C++ both are very popular programming languages. There can be many situations when you might have to export some functionalities that are written in C programming language into your C++ code. Now the biggest question arises while making any project in C and C++ is that- "Can we Mix C and C++ C
3 min read
Full screen OpenCV / GtK application in C++ running on Raspberry PI
Introduction C++, OpenCV and Gtk are a nice triplet to build applications that run on a Raspberry PI, taking images from the camera, process them, display them and have an unlimited user interface. In this article, I will show you a naive path to display camera captures to a full-screen window. In a
9 min read
How to setup OpenGL with Visual Studio 2019 on Windows 10?
OpenGL is a 2D and 3D graphics API that provides a cross-platform application programming interface for a wide variety of computer platforms. It is operating system independent and has a transparent network. Application developers use it to develop high-performing and visually compelling graphics so
4 min read
Competitive Coding Setup for C++ and Python in VS Code using Python Script
Most of us struggle with using heavy software to run C++ and python code and things become more complicated when we have too many files in a folder. In this blog, we are going to create a python script with VS-code-editor that works out to do all your works. It creates the folder + numbers of files
3 min read
Draw an rectangle using OpenCV in C++
In this article, the task is to draw an rectangle using OpenCV in C++. The rectangle() function from OpenCV C++ library will be used. Syntax: rectangle( img, pt1, pt2, color, thickness, line Type, shift) Parameters: image: It is the image on which the rectangle is to be drawn.start(pt1): It is the t
4 min read
Comparing Python with C and C++
In the following article, we will compare the 3 most used coding languages from a beginner's perspective. It will help you to learn basics of all the 3 languages together while saving your time and will also help you to inter shift from one language you know to the other which you don't. Let's discu
6 min read
C++ File Writer-Reader application using Windows Threads
In this article, we will create a simple Writer-Reader application, which uses two threads, one for Writing into the file and another for Reading from the file. Here we will discuss the approach using Win32 Threads in C/C++. A windows thread can be created using the CreateThread() method. Approach:
3 min read
How to Hide and Show a Console Window in C++?
The task is to hide and Show the console window of a C++ program. The program for the same is given below. Note: The results of the following program can only be seen when it is executed on a console. Example: C/C++ Code // C++ program to hide and show a console window #include <iostream> #inc
2 min read
Write on an image using openCV in C++
In this article, we will discuss how to write over an image using OpenCV C++. Function putText() from OpenCV C++ library will be used to write text on an image. Program 1: Below program shows how to write text over a blank background image: C/C++ Code // C++ program to demonstrate the // above appro
2 min read
Create Directory or Folder with C/C++ Program
Problem: Write a C/C++ program to create a folder in a specific directory path. This task can be accomplished by using the mkdir() function. Directories are created with this function. (There is also a shell command mkdir which does the same thing). The mkdir() function creates a new, empty director
2 min read