MEX file maker not working when using < thread > header

3 vues (au cours des 30 derniers jours)
Christopher
Christopher le 19 Déc 2017
Commenté : Walter Roberson le 19 Déc 2017
I've made a fast version of accumarray in C++ and am trying to make a MEX file for it, but it is not working.
I can compile my code in MinGW via "g++ -m64 -std=c++11 -o accum Accumarray5.cpp"
The problem seems to be that I have included the header < thread > for its functions. I attempt to compile the MEX function in MATLAB using:
mex -v COMPFLAGS='$COMPFLAGS -std=c++11' Accumarray5.cpp
The error I get is:
Error using mex
In file included from C:/MATLAB/SupportPackages/R2015b/MW_MinGW_4_9/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/thread:35:0,
from F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp:6:
C:/MATLAB/SupportPackages/R2015b/MW_MinGW_4_9/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or
-std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp: In function 'void mexFunction(int, char**)':
F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp:167:9: error: 'thread' was not declared in this scope
thread t[thread_num]; // thread t[MAX_THREAD];
^
F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp:172:53: error: 't' was not declared in this scope
t[i] = thread(accumulate, ind[k], vals[k], startind, endind, tmpSum[i]); }
^
F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp:174:53: error: 't' was not declared in this scope
for (int i = 0; i < thread_num; ++i) { t[i].join(); // wait for threads to finish execution
^
The undeclared variables it is complaining about should not a problem because the functionality is described in the < thread > header.
Does anyone know what is wrong?
The other info spit out after my attempt at MEX file generation is:
Verbose mode is on.
Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require the use of
-largeArrayDims and remove the -compatibleArrayDims option.
For more information:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
... Looking for compiler 'MinGW64 Compiler (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9').
... Looking for file 'C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\bin\g++.exe' ...Yes.
... Looking for folder 'C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\' ...Yes.
Found installed compiler 'MinGW64 Compiler (C++)'.
Set PATH = C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin;C:\Program Files\MATLAB\R2015b\extern\include\win64;C:\Program Files\MATLAB\R2015b\extern\include;C:\Program Files\MATLAB\R2015b\simulink\include;C:\Program Files\MATLAB\R2015b\lib\win64;C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2015b\runtime\win64;C:\Program Files\MATLAB\R2015b\bin;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Users\Christopher\AppData\Local\Smartbar\Application\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Git\cmd;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\TDM-GCC-64\bin;C:\Program Files (x86)\Skype\Phone\;;C:\Program Files\Docker Toolbox;C:\TDM-GCC-64\bin;
Set INCLUDE = C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\include;
Set LIB = C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\lib;;
Set MW_TARGET_ARCH = win64;
Set LIBPATH = C:\Program Files\MATLAB\R2015b\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\
Options file: C:\Users\Christopher\AppData\Roaming\MathWorks\MATLAB\R2015b\mex_C++_win64.xml
CMDLINE1 : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2015b/extern/include" -I"C:\Program Files\MATLAB\R2015b/simulink/include" -fexceptions -fno-omit-frame-pointer -O -DNDEBUG "F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp" -o C:\Users\CHRIST~1\AppData\Local\Temp\mex_6074947800533816_7768\Accumarray5.obj
CMDLINE2 : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\g++ -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2015b/extern/lib/win64/mingw64/mexFunction.def" C:\Users\CHRIST~1\AppData\Local\Temp\mex_6074947800533816_7768\Accumarray5.obj -L"C:\Program Files\MATLAB\R2015b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o Accumarray5.mexw64
CXX : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\g++
COMPILER : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\g++
DEFINES : -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CXXFLAGS : -fexceptions -fno-omit-frame-pointer
INCLUDE : -I"C:\Program Files\MATLAB\R2015b/extern/include" -I"C:\Program Files\MATLAB\R2015b/simulink/include"
CXXOPTIMFLAGS : -O -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\g++
LINKER : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\\bin\g++
LDFLAGS : -m64 -Wl,--no-undefined
LDTYPE : -shared
LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2015b/extern/lib/win64/mingw64/mexFunction.def"
LIBLOC : C:\Program Files\MATLAB\R2015b\extern\lib\win64\mingw64
LINKLIBS : -L"C:\Program Files\MATLAB\R2015b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas
LDOPTIMFLAGS : -s
LDDEBUGFLAGS : -g
OBJEXT : .obj
LDEXT : .mexw64
SETENV : set COMPILER=g++
set COMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -DMATLAB_MEX_FILE
set OPTIMFLAGS=-O -DNDEBUG
set DEBUGFLAGS=-g
set LINKER=g++
set LINKFLAGS=-m64 -Wl,--no-undefined -shared -L"C:\Program Files\MATLAB\R2015b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -Wl,"C:\Program Files\MATLAB\R2015b/extern/lib/win64/mingw64/mexFunction.def"
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT= -o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\
MATLABROOT : C:\Program Files\MATLAB\R2015b
ARCH : win64
SRC : "F:\Desktop\matlab codes\Radiation2\Accumarray5.cpp"
OBJ : C:\Users\CHRIST~1\AppData\Local\Temp\mex_6074947800533816_7768\Accumarray5.obj
OBJS : C:\Users\CHRIST~1\AppData\Local\Temp\mex_6074947800533816_7768\Accumarray5.obj
SRCROOT : F:\Desktop\matlab codes\Radiation2\Accumarray5
DEF : C:\Users\CHRIST~1\AppData\Local\Temp\mex_6074947800533816_7768\Accumarray5.def
EXP : Accumarray5.exp
LIB : Accumarray5.lib
EXE : Accumarray5.mexw64
ILK : Accumarray5.ilk
MANIFEST : Accumarray5.mexw64.manifest
TEMPNAME : Accumarray5
EXEDIR :
EXENAME : Accumarray5
COMPFLAGS : -std=c++11
OPTIM : -O -DNDEBUG
LINKOPTIM : -s
  3 commentaires
Christopher
Christopher le 19 Déc 2017
It would make complete sense if the -std=c++11 flag was the problem. The following is my xml file. How exactly should it be edited?
<?xml version="1.0" encoding="UTF-8" ?>
<config
Name="MinGW64 Compiler (C++)"
ShortName = "mingw64-g++"
Manufacturer="GNU"
Version="4.x"
Language="C++"
Priority="B"
Location="$MINGWROOT" >
<Details
CompilerExecutable="$CXX"
CompilerDefines="$DEFINES"
CompilerFlags="$CXXFLAGS"
OptimizationFlags="$CXXOPTIMFLAGS"
DebugFlags="$CXXDEBUGFLAGS"
IncludeFlags="$INCLUDE"
LinkerExecutable="$LD"
LinkerFlags="$LDFLAGS"
LinkerLibraries="$LINKLIBS"
LinkerOptimizationFlags="$LDOPTIMFLAGS"
LinkerDebugFlags="$LDDEBUGFLAGS"
CommandLineShell="set MINGW_ROOT_PATH=%MW_MINGW64_LOC%"
CommandLineShellArg=""
CompilerDefineFormatter="-D%s"
LinkerLibrarySwitchFormatter="-l%s;-llib%s"
LinkerPathFormatter="-L%s"
LibrarySearchPath="$$LIB;$$LIBPATH;$$PATH;$$INCLUDE;$MATLABROOT\extern\lib\$ARCH\mingw"
/>
<vars
CMDLINE1="$CXX -c $DEFINES $INCLUDE $CXXFLAGS $OPTIM $SRC -o $OBJ"
CMDLINE2="$LDXX $LDFLAGS $LDTYPE $LINKOPTIM $LINKEXPORT $OBJS $CXXLIBS $LINKLIBS -o $EXE"
CXX="$MINGWROOT\bin\g++"
COMPILER="$CXX"
DEFINES="-m64 $MATLABMEX"
MATLABMEX="-DMATLAB_MEX_FILE "
CXXFLAGS="-fexceptions -fno-omit-frame-pointer"
INCLUDE="-I"$MATLABROOT/extern/include" -I"$MATLABROOT/simulink/include""
CXXOPTIMFLAGS="-O -DNDEBUG"
CXXDEBUGFLAGS="-g"
LDXX="$CXX"
LINKER="$LDXX"
LDFLAGS="-m64 -Wl,--no-undefined"
LDTYPE="-shared"
LINKEXPORT="-Wl,"$MATLABROOT/extern/lib/win64/mingw64/mexFunction.def""
LIBLOC="$MATLABROOT\extern\lib\win64\mingw64"
LINKLIBS="-L"$MATLABROOT\extern\lib\$ARCH\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas"
LDOPTIMFLAGS="-s"
LDDEBUGFLAGS="-g"
OBJEXT=".obj"
LDEXT=".mexw64"
SETENV="set COMPILER=g++
set COMPFLAGS=-c $CXXFLAGS $DEFINES $MATLABMEX
set OPTIMFLAGS=$CXXOPTIMFLAGS
set DEBUGFLAGS=$CXXDEBUGFLAGS
set LINKER=g++
set LINKFLAGS=$LDFLAGS $LDTYPE $LINKLIBS $LINKEXPORT
set LINKDEBUGFLAGS=$LDDEBUGFLAGS
set NAME_OUTPUT= -o "%OUTDIR%%MEX_NAME%%MEX_EXT%""
/>
<client>
<engine
LINKLIBS="$LINKLIBS -llibeng"
LINKEXPORT=""
LDEXT=".exe"
LINKTYPE=""
MATLABMEX=""
LDTYPE=""
/>
</client>
<locationFinder>
<MINGWROOT>
<and>
<envVarExists name="MW_MINGW64_LOC" />
<fileExists name="$$\bin\g++.exe" />
<dirExists name="$$\..\" />
</and>
</MINGWROOT>
</locationFinder>
<env
PATH = "$MINGWROOT\bin;$MATLABROOT\extern\include\$ARCH;$MATLABROOT\extern\include;$MATLABROOT\simulink\include;$MATLABROOT\lib\$ARCH"
INCLUDE = "$MINGWROOT\include"
LIB = "$MINGWROOT\lib;"
MW_TARGET_ARCH = "win64"
LIBPATH="$MATLABROOT\extern\lib\win64"
/>
</config>
Walter Roberson
Walter Roberson le 19 Déc 2017
Notice the
set COMPFLAGS=-c $CXXFLAGS $DEFINES $MATLABMEX
This suggests that instead of setting the COMPFLAGS variable in the mex compile line, that you should set CXXFLAGS instead.

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by