我想要做的是将 MATLAB-Compiler dll/lib 集成到一个新的 c++ 项目中。
我按照以下说明进行操作:如何集成从 MATLAB 生成的 C++ 共享库,该库运行良好(没有构建错误,并且 intelisense 运行良好,因此它会接缝所有必需的信息)。
我正在使用一个非常简单的 mathlab 代码/函数进行测试:
function output = extest( arg1,arg2 )
output = arg1+arg2;
end
以及 matlab 函数的“默认”c++ 代码:
#include "extest.h"
#include <cstdlib>
#include <stdio.h>
int main(int argc, char** argv){
mclmcrInitialize();
if (!mclInitializeApplication(NULL,0)){
std::cerr << "could not initialize the application properly" << std::endl;
return -1;
}
if(!extestInitialize()){
std::cerr << "could not initialize the library properly" << std::endl;
return -1;
}
else{
try{
//code itself (not jet reached therefore removed)
}catch(const mwException& e){
std::cerr << e.what() << std::endl;
return -2;
}
catch(...){
std::cerr << "Unexpected error thrown" << std::endl;
return -3;
}
extestTerminate();
}
mclTerminateApplication();
return 0;
}
在调试器尝试运行该行之后的 e 片刻之后,if(!extestInitialize())
将引发以下错误。
在 DllTestingCpp.exe 中的 0x000002BF72E0EE55 处引发异常:0xC0000005:访问冲突读取位置 0x0000000000000008。
我可以点击 Visual Studioscontinue >
按钮,并在点击 20 次后继续。通过(无需调试)启动代码ctrl + F5
一切正常。
任何想法为什么会在调试模式下发生?或者更好的方法是如何摆脱这个错误?
PS:extest
是我的库名称,使用 Matlab R2017a 64 位和 Visual Studio 2017(使用 x64 调试),