在单独测试我的代码后,我决定最终将其合并到项目中。问题是,当 LabVIEW 2010(SP1,64 位)加载自定义 DLL 时,它遍历依赖项并发现它需要 tbb.dll。最终。嗯,据我所知,LabVIEW 使用它自己的 tbb.dll 版本。它的版本缺少入口点 ?throw_exception_v4@internal@tbb@@YAXW4exception_id@12@@Z
。我之前单独运行过这个函数,它运行良好。 It would appear this is not an unheard of LabVIEW error which hasn't been addressed.
由于这是第三方库的依赖项,我可以不使用 MATLAB 库并从头开始制作所有内容,或者我可以强制 LabVIEW 加载 tbb.dll 的工作版本,这似乎意味着复制 DLL到 Windows 文件夹中。这些都不是可用的解决方案。此外,我们没有 Mathscript 的许可证.有什么想法吗?
以防万一我在修改他们的示例时做错了什么,我的代码的简化版本如下:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include "mat.h"
#include "createMatFile.h"
export "C" int createMatFile(const char *filename, int* dataArray, int count)
{
MATFile *pmat;
mxArray *data;
mwSize dims[2] = {1,1};
//Open the file to write to
pmat = matOpen(filename, "w");
if (pmat == NULL) {
printf("Error creating file %s\n", filename);
printf("(Do you have write permission in this directory?)\n");
return(EXIT_FAILURE);
}
//Convert data to double
double* dataDouble = new double[count];
for(int i=0; i<count; i++)
{
dataDouble[i] = (double)data[i];
}
//Populate the mxArrays
dataArray = mxCreateDoubleMatrix(1,count,mxREAL);
memcpy((void *)(mxGetPr(dataArray)), (void *)dataDouble, sizeof(*dataDouble)*count);
//Put the shape struct in the .mat file
int status = matPutVariable(pmat, "data", dataArray);
if (status != 0) {
printf("%s : Error using matPutVariable on line %d\n", __FILE__, __LINE__);
return(EXIT_FAILURE);
}
//Clean up
delete [] dataDouble;
mxDestroyArray(dataArray);
//Close the file to write to
if (matClose(pmat) != 0) {
printf("Error closing file %s\n",filename);
return(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
.h文件只是函数的原型(prototype)。
最佳答案
因为 LabVIEW 将自己版本的 tbb.dll 安装到 windows 路径并加载它,修复它的唯一方法是将新的 tbb.dll 复制到 system32 文件夹中。这不是一个好的解决方案,因此唯一可能的答案似乎是:
- 使用这个 system32 hack 可能会导致其他问题。
- 创建一些 hack 以在单独的进程中动态加载适当的 DLL,而不从 LabVIEW 加载任何内容,并从该进程调用 MATLAB DLL,然后将计算的值返回给 LabVIEW 进程。由于我的程序只将数据写入文件,因此它不必向 LabVIEW 返回任何内容,从而简化了这一选择。
- 或者干脆停止结合使用 MATLAB 和 LabVIEW。
关于c++ - 从 LabVIEW 调用的 DLL 写入 MATLAB 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25919667/