Tag: crash

exceptions and threads with mingw

If you’re having trouble using exceptions and threads with MingW, here is the solution:

1. Add these compiler options:
-mthreads (enable exception support in threads)
-fexceptions (enable exception handling)

2. Get the latest version of gcc (I have the 4.4.0, see the g++ -v ouput below)

It is very important that you check your gcc version and configuration (-v), because the last version I had 3.4.0 did not work even with the -mthreads.

Using built-in specs.
Target: mingw32
Configured with: ../gcc-4.4.0/configure --enable-languages=c,ada,c++,fortran,jav
a,objc,obj-c++ --disable-sjlj-exceptions --enable-shared --enable-libgcj --enable-libgomp --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --prefix=/mingw --with-gmp=/mingw/src/gmp/root --with-mpfr=/mingw/src/mpfr/root --build=mingw32
Thread model: win32
gcc version 4.4.0 (GCC)

I lost a lot of time trying to debug/fix this, so I hope this helps.