【问题标题】:Writing a MATLAB file from a DLL called by LabVIEW从 LabVIEW 调用的 DLL 写入 MATLAB 文件
【发布时间】:2014-11-13 04:58:30
【问题描述】:

在单独测试了我的代码后,我决定最终将其合并到项目中。问题是,当 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 文件只是函数的原型。

【问题讨论】:

  • 可能是 x32/x64 问题?
  • 我也想过。我们使用的是 64 位版本的 LabVIEW,以及 64 位版本的 MATLAB 库。我的 dll 是为 64 位架构构建的。现在,自从it's not possible to load a 32 bit dll into a 64 bit process 我取消了那个选项。
  • 尝试使用 Labview 加载 dll 库手动加载您需要的 tbb.dll,看看是否有效?
  • 我可以这样做吗? It would appear 我只能通过调用它们来加载 dll,但我从不调用 tbb.dll,MATLAB DLL 会自己调用。我想我可以尝试调用其中一个函数并吞下由此产生的错误,但我认为这不是一个好主意,我不知道这是否真的有效。即使内存中有第二个 tbb.dll,当 libmat.dll 调用 *.dll 调用 ... 调用 tbb.dll 时,它会使用隐式加载,并获取 LabVIEW 的。

标签: c++ matlab dll labview


【解决方案1】:

由于 LabVIEW 将其自己的 tbb.dll 版本安装到 windows 路径并加载它,修复它的唯一方法是将新的 tbb.dll 复制到 system32 文件夹中。这不是一个好的解决方案,因此唯一可能的答案似乎是:

  • 使用这个 system32 hack 可能会导致其他问题。
  • 创建一些 hack 以在单独的进程中动态加载正确的 DLL,而不从 LabVIEW 加载任何内容,并从该进程调用 MATLAB DLL,然后将计算的值返回给 LabVIEW 进程。由于我的程序仅将数据写入文件,因此无需将任何内容返回给 LabVIEW,从而简化了这一选择。
  • 或者干脆停止同时使用 MATLAB 和 LabVIEW。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多