gpt4 book ai didi

c++ - 仅在调试期间在 C++ 中初始化 matlab 编译器 dll/lib 时发生访问冲突

转载 作者:行者123 更新时间:2023-11-30 03:30:49 25 4
gpt4 key购买 nike

我想做的是将 MATLAB-Compiler dll/lib 集成到一个新的 C++ 项目中。

我遵循了这条指令:How do I integrate my C++ shared Library generated from MATLAB哪些接缝工作良好(没有构建错误,intelisense 工作良好,所以它接缝所有需要的信息都在那里)。

我正在使用一个非常简单的数学实验室代码/函数进行测试:

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()) 行后不久,将抛出以下错误。

Exception thrown at 0x000002BF72E0EE55 in DllTestingCpp.exe: 0xC0000005: Access violation reading location 0x0000000000000008.

enter image description here

我可以点击 visual studios continue > 按钮,假设点击 20 次后它会继续。通过 ctrl + F5 启动代码(无需调试)一切正常。

知道为什么在 Debug模式下会发生这种情况吗?或者更好的方法是如何消除此错误?

PS:extest 是我的库名称,使用 Matlab R2017a 64 位和 Visual Studio 2017(使用 x64 调试),

最佳答案

对我来说同样的问题(Matlab2017 + VS 2015)。可能与 MATLAB 使用的 java 有一些冲突。

我已经修复了

const char *args[] = {"-nojvm"};
const int count = sizeof(args) / sizeof(args[0]);
mclInitializeApplication(args, count))

代替

mclInitializeApplication(NULL,0)

关于c++ - 仅在调试期间在 C++ 中初始化 matlab 编译器 dll/lib 时发生访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44709644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com