If you develop under Windows with C/C++ you do not necessarily have to use Microsoft Visual Studio. This blog series shows alternatives based on free software and available for all operating systems. This can be an advantage if a team uses different operating systems and still wants to use the same toolchain. Furthermore, the alternatives are free of charge.
To demonstrate the use of the presented toolchains we use the Google Test demo project on GitHub.
MinGW stands for Minimalist GNU for Windows and is a collection of open source tools for software development for Windows. The included tools are:
The Gnu Compiler Collection (GCC) with compilers for C, C++, Fortran and ADA
Tools for creating archives, dynamically loadable libraries and executable files
Gnu Debugger (GDB) and other tools like gcov for code coverage analysis.
Unlike Cygwin, which we will cover in the next blog, the programs you create with MinGW do not use their own runtime library. Instead, they use the Microsoft libraries that are part of every Windows installation. Therefore, there are no licensing problems when using MinGW.
MinGW is available for Linux and MacOS, allowing cross compilation for Windows on these platforms.
MinGW-w64 was started in 2005 by OneVision to port an Objective-C application to Windows. The authors of MinGW did not want to adopt the code because of licensing concerns, as OpenVision developed the Windows API using a clean room implementation. Therefore OneVision released the project as a fork of MinGW on Sourceforge in 2008. Currently there are about 20 developers working on the project. MinGW-w64, unlike MinGW, can also create 64-bit binaries and supports more features of the Windows API. Also the attempt of the author to translate Google Test with MinGW failed. With MinGW-w64 this is possible without problems. Like MinGW, MinGW-w64 is available for all common operating systems.
Basically there are two ways to implement concurrency: Either you use the Windows API (_beginthread, _cwait, etc.) to create and manage threads or you use the Posix-compliant Pthreads library. The advantage of the latter variant is that the code can be compiled for any Posix-compliant system such as Linux and MacOS.
Unfortunately, the C++ Thread support library is not implemented by the standard library provided with MinGW-w64. However, there is an implementation for MinGW on GitHub: mingw-std-threads. Another portable alternative is Boost Thread.
Google Test Demo Project
In the following we will download, translate and run the demo project step by step. For this we need:
After installing all required packages, we clone the demo project:
git clone https://github.com/bast/gtest-demo
Then we create a directory in which we will translate the project and change to this directory:
cd gtest-demo build
The demo project uses an old Google test release that does not work with MinGW. Therefore we change the Google Test version from 1.8.0 to 1.10.0. To do this we open the file gtest-demo/cmake/googletest-download.cmake and change line 10:
@@ -12,7 +12,7 @@ ExternalProject_Add(
Now we let CMake create the ninja build system:
cmake -G Ninja ..
And translate the project with:
cmake –build .
Now we can run the demo project:
And when we have done everything right, we will see this test report:
[==========] Running 2 tests from 1 test suite.
[———-] Global test environment set-up.
[———-] 2 tests from example
[ RUN ] example.subtract
[ OK ] example.subtract (0 ms)
[ RUN ] example.add
[ OK ] example.add (0 ms)
[———-] 2 tests from example (11 ms total)
[———-] Global test environment tear-down
[==========] 2 tests from 1 test suite ran. (30 ms total)
[ PASSED ] 2 tests.
When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.