Skip to content

Troubleshooting MinGW

anokn edited this page Nov 19, 2021 · 4 revisions

Compilation errors or linkage errors by std::filesystem

Many MinGW distros now have some problems with std::filesystem. To fix the problems, the simplest way is to use MSYS2(http://www.msys2.org/) and GCC 8.2 or later.

To fix the problems using other MinGW distros, please rebuild nana with -std=c++11/-std=c++14. When C++17 is required, -std=c++17 is still allowed if you use boost::filesystem /nana::filesystem instead of std::filesystem. There is simple troubleshooting guide that should resolve the problems.

//Generate a makefile, the generated makefile default enables C++17
cmake C:\nana -G "MinGW Makefiles" -DNANA_CMAKE_NANA_FILESYSTEM_FORCE=1

//Then call make to build nana
mingw32-make

//Compile your program. Suppose the libnana.a is in current folder.
g++ -o program program.cpp -s -std=c++17 -L./ -lnana -lgdi32 -lcomdlg32 -IC:\nana\include -DNANA_FILESYSTEM_FORCE
  • -DNANA_CMAKE_NANA_FILESYSTEM_FORCE=1 is to generate a makefile that uses nana::filesystem.
  • -DNANA_FILESYSTEM_FORCE is to enable nana::filesystem for your program.

But nana::filesystem is a compact implementation of std::filesystem. When you need complete functionalities on std::filesystem, we recommand you to use boost::filesystem. The two options for boost::filesystem are:

  • -DNANA_CMAKE_BOOST_FILESYSTEM_FORCE=1
  • -DBOOST_FILESYSTEM_FORCE

Using MSYS2

There are 2 major issues on most MinGW distros, std::filesystem and COM. The MSYS2 is a recommanded distro for Nana C++ Library.

Installing MSYS2 and MinGW

Frist of all, please download msys2-x86_64_xxx.exe, then install it(Suppose it is installed in C:\msys64).

Run the msys2(c:\msys64\msys2_shell.cmd -msys), update the package database.

# Update the package database
pacman -Syu

# It may prompt you to close the terminal window and run msys2 again
pacman -Su

Now, install MinGW

#Install full toolchain, it may contain 17 packages.
pacman -S mingw-w64-x86_64-toolchain

#If you don't need toolchain for full GCC then you can install only C++
pacman -S mingw-w64-x86_64-gcc

Compiling Nana Using Code::Blocks

First, we need to set compilers for Code::Blocks. Configuration of Code::Blocks

Then right-click the nana project in Workspace, choose the Build options..., check Have g++ follow the comming C++1z(aka C++17) ISO C++ Language Standard [-std=c++1z]. Now we can build the Nana.

Compiling Nana Using Makefile

In MSYS2's MinGW distro, there is not a make or mingw32-make contained in its bin directory. so we need to install make in MSYS2 and compile Nana in MSYS2. Run MSYS2 with g++ enabled(C:\msys2\msys2_shell.cmd -mingw64)

pacman -S make

Now, enter the nana/build/makefile folder, run

make -j4

The default makefile only enables -std=c++11, please modify it if -std=c++17 is required.

Compiling Nana Using CMake

In MSYS2's MinGW distro, there is not a make or mingw32-make contained in its bin directory. so we need to install make in MSYS2 and compile Nana in MSYS2. Run MSYS2 with g++ enabled(C:\msys2\msys2_shell.cmd -mingw64)

pacman -S cmake make

Now, enter the nana folder, run

mkdir cmake-build && cd cmake-build
cmake .. -G "Unix Makefiles"
make -j4