The Mysteries of MinGW C++ 11
Posted: Wed Jul 31, 2013 1:33 pm
This is a follow up to the Setting up MinGW post showing how to get Zeus to work with MinGW.
Lets now consider this C++ 11 code:
Using the compiler settings from the earlier post:
will result in the following error message:
So to get this C++ 11 code to compile we need to add the -std=c++11 option to the command line.
While we're at it lets add a few other options and make the C/C++ Document Type compiler command line read as follows:
With these compiler options the compile now works and it produces the test.exe file without any errors or warnings:
But if we now try and run that executable it runs fine, without error, but produces no output.
Then if we remove the C++ 11 code and use nothing more than a printf it compiles, runs and produces the expected output.
So what could be going wrong
Well, after a long period of Google searching, it appears the MinGW requires a few dll files to run properly.
If it doesn't find those dll files it does not complain, but rather it runs without error but it just doesn't work.
So what is the magic sauce that makes things work
Based on the folder details described in the earlier Setting up MinGW post.
There is a set of runtime dlls found in the following directory:
If we now use the Zeus Tools, DOS Command Line menu and in the resulting command line dialog we set the arguments to be
and the working directory to be we now see the expected output:
What is confusing is that folder is already in the system PATH environment variable so the should have been able to find them 
I'm going to have to spend a little more time trying to get my head around how MinGW actually works
Cheers Jussi
Lets now consider this C++ 11 code:
Code: Select all
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
vec.push_back(4);
for (int i : vec )
{
cout << i << "\n";
}
}
Code: Select all
g++ "$fn" -o "$fdd$fb.exe"
Code: Select all
C:\temp\test.cpp: In function 'int main()':
C:\temp\test.cpp:14:18: error: range-based 'for' loops are not allowed in C++98 mode
for (int i : vec )
While we're at it lets add a few other options and make the C/C++ Document Type compiler command line read as follows:
Code: Select all
g++ -x c++ -Wall -std=c++11 "$fn" -o "$fdd$fb.exe"
Code: Select all
Directory of c:\temp
31/07/2013 11:13 PM 99,711 test.exe
1 File(s) 99,711 bytes
0 Dir(s) 1,603,624,960 bytes free
Then if we remove the C++ 11 code and use nothing more than a printf it compiles, runs and produces the expected output.
So what could be going wrong

Well, after a long period of Google searching, it appears the MinGW requires a few dll files to run properly.
If it doesn't find those dll files it does not complain, but rather it runs without error but it just doesn't work.
So what is the magic sauce that makes things work

Based on the folder details described in the earlier Setting up MinGW post.
There is a set of runtime dlls found in the following directory:
Code: Select all
C:\Program Files\mingw-builds\x32-4.8.1-posix-dwarf-rev3\mingw32\bin\
Code: Select all
c:\temp\test.exe
Code: Select all
C:\Program Files\mingw-builds\x32-4.8.1-posix-dwarf-rev3\mingw32\bin\
Code: Select all
1
2
3
4

I'm going to have to spend a little more time trying to get my head around how MinGW actually works

Cheers Jussi