我要做的是将/lib集成到一个新的c++项目中。
我遵循了这样的指令:如何集成由MATLAB生成的C++共享库,它的接缝工作良好(没有构建错误和智能是好的,所以它缝合了所有所需的信息)。
我使用一个非常简单的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;
}
在调试器尝试运行行if(!extestInitialize())
之后的几分钟后,将引发以下错误。
在DllTestingCpp.exe: 0xC0000005:访问冲突读取位置0x00000000000008中在0x000002BF72E0EE55引发的异常。
我可以点击视觉工作室的continue >
按钮,它是继续后,让我们说,20次点击它。通过ctrl + F5
启动代码(不进行调试)一切都很好。
知道为什么在调试模式下会发生这种情况吗?或者更好的方法,我可以消除这个错误?
PS:extest
是我的库名,使用Matlab R2017a 64 with和Visual 2017 (用x64调试),
发布于 2018-01-25 10:12:56
对于我来说,同样的问题(Matlab2017 + VS 2015)。可能与MATLAB使用的java有一些冲突。
我已经修好了
const char *args[] = {"-nojvm"};
const int count = sizeof(args) / sizeof(args[0]);
mclInitializeApplication(args, count))
而不是
mclInitializeApplication(NULL,0)
发布于 2019-07-17 16:08:35
我也有同样的问题(使用VS2019),我在这里找到了以下答案:https://uk.mathworks.com/matlabcentral/answers/182851-how-do-i-integrate-my-c-shared-library-generated-from-matlab-r2013b-in-visual-studio-2013
我遇到了同样的问题,并向Mathworks报告了此事。他们响应说,对于VS2013和更高版本,调试器在0xc0000005发生时被设置为中断,即使在本例中它是由JVM处理的。修复方法是转到Debug>Windows>Exception Settings>Win32并取消检查'0xc0000005访问冲突‘。在VS2012中,默认情况下不检查此设置。
这似乎没问题吧。
https://stackoverflow.com/questions/44709644
复制相似问题