MATLAB R2016b - MEX 无法编译 C++ 代码
MATLAB R2016b - MEX fails to compile C++ code
我的 堆满了很多信息。部分原因是这个问题,希望它本身有更多信息会更有意义。
我正在尝试使用 MATLAB R2016b 中的 mex
在 Windows 上编译 C++03 代码。
当我尝试这样做时,出现以下错误:
Error using mex
cpp_mexapi_version.o: In function `mexfilerequiredapiversion':
C:/Progra~1/MATLAB/R2016b/extern/version/cpp_mexapi_version.cpp:4: multiple definition of `mexfilerequiredapiversion'
C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj:cpp_mexapi_version.cpp:(.text+0x0): first defined here
myclass.o: In function `MyClass::MyClass(int, double*, int, int, int*, double, int, double, double, int, bool, char)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:67: undefined reference to `__imp___acrt_iob_func'
C:\msys64\home\myName\Desktop\test/myclass.cpp:110: undefined reference to `__imp___acrt_iob_func'
C:\msys64\home\myName\Desktop\test/myclass.cpp:121: undefined reference to `__imp___acrt_iob_func'
myclass.o: In function `MyClass::MyClass(int, double*, int, int*, int, double, double, int, char)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:139: undefined reference to `__imp___acrt_iob_func'
C:\msys64\home\myName\Desktop\test/myclass.cpp:178: undefined reference to `__imp___acrt_iob_func'
myclass.o:C:\msys64\home\myName\Desktop\test/myclass.cpp:189: more undefined references to `__imp___acrt_iob_func' follow
myclass.o: In function `MyAssertionClass::MyAssertionClass(char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:1014: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream()'
myclass.o: In function `MyAssertionClass::MyAssertionClass(char const*, int, char const*)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:1029: undefined reference to `std::__cxx11::basic_ostringstream<char,
std::char_traits<char>, std::allocator<char> >::basic_ostringstream()'
collect2.exe: error: ld returned 1 exit status
这是失败之前的详细日志:
>> mex -v COMPFLAGS='$COMPFLAGS -std=c++03' -IC:\ourLibraryLocation myTargetMex.cpp myclass.o (a few other .o files here) cpp_mexapi_version.o
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:\TDM-GCC-64').
... Looking for file 'C:\TDM-GCC-64\bin\g++.exe' ...Yes.
... Looking for folder 'C:\TDM-GCC-64' ...Yes.
Found installed compiler 'MinGW64 Compiler (C++)'.
Set PATH = C:\TDM-GCC-64\bin;C:\Program Files\MATLAB\R2016b\extern\include\win64;C:\Program Files\MATLAB\R2016b\extern\include;C:\Program Files\MATLAB\R2016b\simulink\include;C:\Program Files\MATLAB\R2016b\lib\win64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\avs\bin;C:\Program Files\avs\bin32;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\MATLAB\R2016b\bin;C:\TDM-GCC-64\bin;C:\Users\myName\AppData\Local\Microsoft\WindowsApps;
Set INCLUDE = C:\TDM-GCC-64\include;C:\TDM-GCC-64\include;
Set LIB = C:\TDM-GCC-64\lib;;C:\TDM-GCC-64\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2016b\extern\lib\win64;C:\Program Files\MATLAB\R2016b\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\TDM-GCC-64
Options file: C:\Users\myName\AppData\Roaming\MathWorks\MATLAB\R2016b\mex_C++_win64.xml
CMDLINE2 : C:\TDM-GCC-64\bin\g++ -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj myclass.o (a few other .o files here) cpp_mexapi_version.o -L"C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myTargetMex.mexw64
CXX : C:\TDM-GCC-64\bin\g++
COMPILER : C:\TDM-GCC-64\bin\g++
DEFINES : -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CXXFLAGS : -fexceptions -fno-omit-frame-pointer -std=c++11
INCLUDE : -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include"
CXXOPTIMFLAGS : -O -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : C:\TDM-GCC-64\bin\g++
LINKER : C:\TDM-GCC-64\bin\g++
LDFLAGS : -m64 -Wl,--no-undefined
LDTYPE : -shared
LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/mexFunction.def"
LINKEXPORTVER : -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/exportsmexfileversion.def"
LIBLOC : C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64
LINKLIBS : -L"C:\Program Files\MATLAB\R2016b\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 -std=c++11 -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\R2016b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/mexFunction.def"
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT= -o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\TDM-GCC-64
MATLABROOT : C:\Program Files\MATLAB\R2016b
ARCH : win64
SRC : C:\Users\myName\Desktop\test\myTargetMex.cpp;"C:\Program Files\MATLAB\R2016b\extern\version\cpp_mexapi_version.cpp"
OBJ : C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj;C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj
OBJS : C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj myclass.o (a few other .o files here) cpp_mexapi_version.o
SRCROOT : C:\Users\myName\Desktop\test\myTargetMex
DEF : C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.def
EXP : myTargetMex.exp
LIB : myTargetMex.lib
EXE : myTargetMex.mexw64
ILK : myTargetMex.ilk
MANIFEST : myTargetMex.mexw64.manifest
TEMPNAME : myTargetMex
EXEDIR :
EXENAME : myTargetMex
COMPFLAGS : -std=c++03
OPTIM : -O -DNDEBUG
LINKOPTIM : -s
CMDLINE1_0 : C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG C:\Users\myName\Desktop\test\myTargetMex.cpp -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj
CMDLINE1_1 : C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\Program Files\MATLAB\R2016b\extern\version\cpp_mexapi_version.cpp" -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C++)'.
C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG C:\Users\myName\Desktop\test\myTargetMex.cpp -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj
C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\Program Files\MATLAB\R2016b\extern\version\cpp_mexapi_version.cpp" -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj
C:\TDM-GCC-64\bin\g++ -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj myclass.o (a few other .o files here) cpp_mexapi_version.o -L"C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myTargetMex.mexw64
明确地说,MyClass 只是包含在 myTargetMex 中的另一个 class。它恰好是第一个,所以当尝试编译时它自然是第一个失败的东西。 (据我所知)
感谢您的帮助!
结果如下:
我需要使用 $CXXFLAGS 而不是 $COMPFLAGS(详细输出显示 COMPFLAGS 从未出现在此处,但 CXXFLAGS 出现)
执行 CXXFLAGS='$CXXFLAGS -std=c++03'
只是 将 标志添加到现有标志集。 (呃,但我错过了这个)默认情况下,现有的标志集包括 -std=c++11
。从技术上讲,最后一个只是覆盖了旧的,但看起来仍然很奇怪。更好的方法是:CXXFLAGS='-fexceptions -fno-omit-frame-pointer -std=c++03'
,所以我包含了它已有的所有内容,但只是替换了 c++ 标准部分。您可以对任何要更改的内容执行相同的操作。就像 CXXOPTIMFLAGS='-O0 -DNDEBUG'
只会将 -O
替换为 -O0
旁注:如果您的项目混合使用 C 和 CPP,那就太麻烦了。帮自己一个忙,将所有 .C 文件更改为 .CPP。我们有那个,当 MEX 试图编译 .C 文件时,它使用 GCC 而不是 G++,并且有一个嘶嘶声。最好避免这种情况。提醒一下,旧的 mexFunction() 入口点在 .C 文件中完全正常。 mexFunction() 不需要在.C 文件中!
非常感谢 Cris Luengo 他再次用他的 MATLAB 和 MEX 文件知识拯救了我。 :) 如果他提出一个解决方案,我会将他的解决方案标记为答案。
我的
我正在尝试使用 MATLAB R2016b 中的 mex
在 Windows 上编译 C++03 代码。
当我尝试这样做时,出现以下错误:
Error using mex
cpp_mexapi_version.o: In function `mexfilerequiredapiversion':
C:/Progra~1/MATLAB/R2016b/extern/version/cpp_mexapi_version.cpp:4: multiple definition of `mexfilerequiredapiversion'
C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj:cpp_mexapi_version.cpp:(.text+0x0): first defined here
myclass.o: In function `MyClass::MyClass(int, double*, int, int, int*, double, int, double, double, int, bool, char)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:67: undefined reference to `__imp___acrt_iob_func'
C:\msys64\home\myName\Desktop\test/myclass.cpp:110: undefined reference to `__imp___acrt_iob_func'
C:\msys64\home\myName\Desktop\test/myclass.cpp:121: undefined reference to `__imp___acrt_iob_func'
myclass.o: In function `MyClass::MyClass(int, double*, int, int*, int, double, double, int, char)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:139: undefined reference to `__imp___acrt_iob_func'
C:\msys64\home\myName\Desktop\test/myclass.cpp:178: undefined reference to `__imp___acrt_iob_func'
myclass.o:C:\msys64\home\myName\Desktop\test/myclass.cpp:189: more undefined references to `__imp___acrt_iob_func' follow
myclass.o: In function `MyAssertionClass::MyAssertionClass(char const*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:1014: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::basic_ostringstream()'
myclass.o: In function `MyAssertionClass::MyAssertionClass(char const*, int, char const*)':
C:\msys64\home\myName\Desktop\test/myclass.cpp:1029: undefined reference to `std::__cxx11::basic_ostringstream<char,
std::char_traits<char>, std::allocator<char> >::basic_ostringstream()'
collect2.exe: error: ld returned 1 exit status
这是失败之前的详细日志:
>> mex -v COMPFLAGS='$COMPFLAGS -std=c++03' -IC:\ourLibraryLocation myTargetMex.cpp myclass.o (a few other .o files here) cpp_mexapi_version.o
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:\TDM-GCC-64').
... Looking for file 'C:\TDM-GCC-64\bin\g++.exe' ...Yes.
... Looking for folder 'C:\TDM-GCC-64' ...Yes.
Found installed compiler 'MinGW64 Compiler (C++)'.
Set PATH = C:\TDM-GCC-64\bin;C:\Program Files\MATLAB\R2016b\extern\include\win64;C:\Program Files\MATLAB\R2016b\extern\include;C:\Program Files\MATLAB\R2016b\simulink\include;C:\Program Files\MATLAB\R2016b\lib\win64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\avs\bin;C:\Program Files\avs\bin32;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Enterprise Vault\EVClient\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\MATLAB\R2016b\bin;C:\TDM-GCC-64\bin;C:\Users\myName\AppData\Local\Microsoft\WindowsApps;
Set INCLUDE = C:\TDM-GCC-64\include;C:\TDM-GCC-64\include;
Set LIB = C:\TDM-GCC-64\lib;;C:\TDM-GCC-64\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2016b\extern\lib\win64;C:\Program Files\MATLAB\R2016b\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\TDM-GCC-64
Options file: C:\Users\myName\AppData\Roaming\MathWorks\MATLAB\R2016b\mex_C++_win64.xml
CMDLINE2 : C:\TDM-GCC-64\bin\g++ -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj myclass.o (a few other .o files here) cpp_mexapi_version.o -L"C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myTargetMex.mexw64
CXX : C:\TDM-GCC-64\bin\g++
COMPILER : C:\TDM-GCC-64\bin\g++
DEFINES : -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CXXFLAGS : -fexceptions -fno-omit-frame-pointer -std=c++11
INCLUDE : -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include"
CXXOPTIMFLAGS : -O -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : C:\TDM-GCC-64\bin\g++
LINKER : C:\TDM-GCC-64\bin\g++
LDFLAGS : -m64 -Wl,--no-undefined
LDTYPE : -shared
LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/mexFunction.def"
LINKEXPORTVER : -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/exportsmexfileversion.def"
LIBLOC : C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64
LINKLIBS : -L"C:\Program Files\MATLAB\R2016b\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 -std=c++11 -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\R2016b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/mexFunction.def"
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT= -o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\TDM-GCC-64
MATLABROOT : C:\Program Files\MATLAB\R2016b
ARCH : win64
SRC : C:\Users\myName\Desktop\test\myTargetMex.cpp;"C:\Program Files\MATLAB\R2016b\extern\version\cpp_mexapi_version.cpp"
OBJ : C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj;C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj
OBJS : C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj myclass.o (a few other .o files here) cpp_mexapi_version.o
SRCROOT : C:\Users\myName\Desktop\test\myTargetMex
DEF : C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.def
EXP : myTargetMex.exp
LIB : myTargetMex.lib
EXE : myTargetMex.mexw64
ILK : myTargetMex.ilk
MANIFEST : myTargetMex.mexw64.manifest
TEMPNAME : myTargetMex
EXEDIR :
EXENAME : myTargetMex
COMPFLAGS : -std=c++03
OPTIM : -O -DNDEBUG
LINKOPTIM : -s
CMDLINE1_0 : C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG C:\Users\myName\Desktop\test\myTargetMex.cpp -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj
CMDLINE1_1 : C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\Program Files\MATLAB\R2016b\extern\version\cpp_mexapi_version.cpp" -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C++)'.
C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG C:\Users\myName\Desktop\test\myTargetMex.cpp -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj
C:\TDM-GCC-64\bin\g++ -c -DMX_COMPAT_32 -m64 -DMATLAB_MEX_FILE -IC:\ourLibraryLocation -I"C:\Program Files\MATLAB\R2016b/extern/include" -I"C:\Program Files\MATLAB\R2016b/simulink/include" -fexceptions -fno-omit-frame-pointer -std=c++11 -O -DNDEBUG "C:\Program Files\MATLAB\R2016b\extern\version\cpp_mexapi_version.cpp" -o C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj
C:\TDM-GCC-64\bin\g++ -m64 -Wl,--no-undefined -shared -s -Wl,"C:\Program Files\MATLAB\R2016b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\myTargetMex.obj C:\Users\myName\AppData\Local\Temp\mex_53351148310745_8852\cpp_mexapi_version.obj myclass.o (a few other .o files here) cpp_mexapi_version.o -L"C:\Program Files\MATLAB\R2016b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myTargetMex.mexw64
明确地说,MyClass 只是包含在 myTargetMex 中的另一个 class。它恰好是第一个,所以当尝试编译时它自然是第一个失败的东西。 (据我所知)
感谢您的帮助!
结果如下:
我需要使用 $CXXFLAGS 而不是 $COMPFLAGS(详细输出显示 COMPFLAGS 从未出现在此处,但 CXXFLAGS 出现)
执行
CXXFLAGS='$CXXFLAGS -std=c++03'
只是 将 标志添加到现有标志集。 (呃,但我错过了这个)默认情况下,现有的标志集包括-std=c++11
。从技术上讲,最后一个只是覆盖了旧的,但看起来仍然很奇怪。更好的方法是:CXXFLAGS='-fexceptions -fno-omit-frame-pointer -std=c++03'
,所以我包含了它已有的所有内容,但只是替换了 c++ 标准部分。您可以对任何要更改的内容执行相同的操作。就像CXXOPTIMFLAGS='-O0 -DNDEBUG'
只会将-O
替换为-O0
旁注:如果您的项目混合使用 C 和 CPP,那就太麻烦了。帮自己一个忙,将所有 .C 文件更改为 .CPP。我们有那个,当 MEX 试图编译 .C 文件时,它使用 GCC 而不是 G++,并且有一个嘶嘶声。最好避免这种情况。提醒一下,旧的 mexFunction() 入口点在 .C 文件中完全正常。 mexFunction() 不需要在.C 文件中!
非常感谢 Cris Luengo 他再次用他的 MATLAB 和 MEX 文件知识拯救了我。 :) 如果他提出一个解决方案,我会将他的解决方案标记为答案。