Using MinGW compiler and Open MP

49 views (last 30 days)
Øyvind on 15 Apr 2016
Commented: Rik on 13 Jun 2022
I'm using Matlab 2015b and try to create a mex function using the MinGW compiler with OpenMP activated:
mex -setup:'C:\Program Files\MATLAB\R2015b\bin\win64\mexopts\mingw64.xml' C
mex -V CFLAGS="\$CFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp" test_openmp_Omp.c
The last call to mex produces the following error message:
Error using mex
gcc: error: \-fexceptions: No such file or directory
-fexceptions is supposed to be a flag to the compiler, but it seems that the \ makes the compiler misinterprete it as a file or directory. Perhaps because of a bug in the mingw64.xml file.
The last part of the output from mex: (seems to be the call to gcc)
Building with 'MinGW64 Compiler (C)'.
C:\TDM-GCC-64\\bin\gcc -c -DMX_COMPAT_32 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2015b/extern/include" -I"C:\Program Files\MATLAB\R2015b/simulink/include" -I"C:\Program Files\MATLAB\R2015b/extern\lib\win64\mingw64" \-fexceptions -fno-omit-frame-pointer -fopenmp -fexceptions -O -DNDEBUG \\\H12_HOME01\160725\personal\MATLAB\myToolbox\convolution\test_openmp_Omp.c -o C:\Users\160725\AppData\Local\Temp\mex_253195324901869_11764\test_openmp_Omp.obj
Any help would be greatly appreciated.
Rik on 13 Jun 2022
Comment posted as flag by Ming ZHANG:
Thank you so much, it works!

Sign in to comment.

Answers (1)

Jeppe Druedahl
Jeppe Druedahl on 19 Apr 2016
Edited: Jeppe Druedahl on 19 Apr 2016
I have found a somewhat odd solution.
1. Install TDM-GCC independently from (I installed 5.1.0)
2. Link til libgomp.a in that installation when compilling your mex file.
I specifically used:
mex C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\5.1.0\libgomp.a CXXFLAGS="$CXXFLAGS -std=c++11 -fopenmp" test_openmp.cpp
Clement Val
Clement Val on 11 Sep 2020
Just a quick comment in passing: I also had success linking to the runtime library provided with the MinGW installation included in the MATLAB Support Package.
In my case, the mex command was this:
mex C:\ProgramData\MATLAB\SupportPackages\R2020a\3P.instrset\mingw_w64.instrset\lib\gcc\x86_64-w64-mingw32\6.3.0\libgomp.a -v commonTimePar.c CFLAGS='$CFLAGS -fopenmp' -LDFLAGS='$LDFLAGS -fopenmp'

Sign in to comment.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!