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