Error while compiling mex wrapper in debug mode

조회 수: 15 (최근 30일)
Kishore
Kishore 2012년 7월 9일
댓글: DanielFromIllinois 2021년 9월 30일
Hello, i am using MATLAb 2011 b 32 bit . and MSVC 2011 EXpress edition. ( SDK 7.0)
1) Now, i have 3 static libraries built in Release mode. When i compile and link them, i see no issue, everything works fine.
2) But when the compile the mex wrapper ( when the libraries are in debug mode), i get an error test1.lib( test.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in mexWrapper.obj .
Then i defined _ITERATOR_DEBUG_LEVEL = 2 in mexWrapper.cpp. But then i get a new compiler error
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\yvals.h(113) : fatal error C1189: #error : _ITERATOR_DEBUG_LEVEL > 1 is not supported in release mode.
My question is, do i need to define something in the build options for debug mode?
Currently i am using
'mex -win32 -g -v -Dmex ', ...
'-D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE ', ...
'-D_CRT_SECURE_NO_WARNINGS ', ...
'LINKFLAGS="$LINKFLAGS /NODEFAULTLIB:MSVCRTD" ', ...
'CFLAGS="$CFLAGS -std=c99" '...
];
Please let me know anything that could help me build this.
Thanks!, Kishore.

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2012년 8월 6일
Instead of modifying mexWrapper.cpp, perhaps you should modify mexopts.bat to define _ITERATOR_DEBUG_LEVEL=2 and _SECURE_SCL=1. This will require the program to be compilied in debug mode (not in release mode). This is accomplished by including _DEBUG as another compiler flag. An example of the line defining COMPFLAGS in the mexopts.bat file follows:
COMPFLAGS=/c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE / D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=1 /D_ITERATOR_DEBUG_LEVEL=2 / DMATLAB_MEX_FILE /nologo /MD /D_DEBUG
  댓글 수: 1
DanielFromIllinois
DanielFromIllinois 2021년 9월 30일
Is there someplace to find documentation on these flags? Is it part of the compiler's documentation or matlab's mex or what?
Also, I didn't have a mexopts.bat file instead I had a mex_C++_win64.xml that I think is because i'm using VS2019 C++ compilers.

댓글을 달려면 로그인하십시오.


Boyang
Boyang 2013년 12월 7일
Hi, I ran into a similar problem. After setting both flags, I'm still seeing the error.
my mexopts.bat file:
set COMPFLAGS=/c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=1 /D_ITERATOR_DEBUG_LEVEL=2 /DMATLAB_MEX_FILE /nologo /MTd /D_DEBUG set OPTIMFLAGS=/O2 /Oy- /DNDEBUG
error message:
blitz.lib(globals.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in qobj.obj blitz.lib(globals.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MTd_StaticDebug' in qobj.obj Creating library C:\Users\boyangz\AppData\Local\Temp\mex_RK2lbn\templib.x and object C:\Users\boyangz\AppData\Local\Temp\mex_RK2lbn\templib.exp LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library qobj.mexw64 : fatal error LNK1319: 2 mismatches detected
C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: Link of 'qobj.mexw64' failed.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by