5

我在 MATLAB 中创建了一个 DLL,它为我的 .m 函数提供了一个接口。

现在我想将它与 MCR 运行时库一起使用。(MCR = Matlab 编译器运行时)。

我从一个 C 例程中调用这个 DLL,该例程最终用 GCC (MinGW) 编译成一个包装 DLL。

现在我的函数变成了两种形式:

extern LIB_XYZ_C_API 
bool MW_CALL_CONV mlxGet_path(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
extern LIB_XYZ_C_API bool MW_CALL_CONV mlfGet_path(int nargout, mxArray** p);

从这些中我选择了后者,因为前者似乎是一种“老式/传统”。

我这样称呼它:

char get_path(LStrHandle path)
{
    char mret = init_XYZ(); // here I call mclmcrInitialize(), mclInitializeApplication(NULL, 0) etc.
    if (mret) return mret;
    mret = 2;
    // here the relevant part begins
    mxArray * mxpath = NULL; // set it to NULL and let the callee allocate it
    bool bret = mlfGet_path(1, &mxpath);
    // now I convert the mxpath to a string
    // What do I do with the mxpath afterwards?
    // I try to free it with
    mxDestroyArray(mxpath);
    return mret;
}

问题就从这里开始了mxDestroyArray()在链接过程中找不到:

undefined reference to `mxDestroyArray'

如果我手动添加-llibmx到构建过程中,构建会运行,但随后libmx.dll无法找到,因为 MCR 仅放入$MCR\runtime\win32路径中,但没有放入路径$MCR\bin\win32libmx.dll

我能做些什么?

使用自编译 DLL 时是否必须选择不同的“销毁”函数?

还是我必须在路径上鬼混?(我不希望如此……)

此外,还有其他一些功能缺失,但我认为这会以同样的方式解决:

mxGetNumberOfElements
mxIsDouble
mxGetPr
mxGetM
mxGetN
mxGetData
mxIsChar
mxIsCell
mxDestroyArray
mxGetCell_730
mxSetCell_730
mxGetString_730
mxCalcSingleSubscript_730
mxGetNumberOfDimensions_730
mxCreateDoubleMatrix_730
mxCreateNumericMatrix_730
mxCreateCellMatrix_730
4

1 回答 1

0

我发现使用 MCR 或安装 MATLAB 安装会有很大的不同。

  1. 使用链接器-lmclmcrrt代替-lmx并使用正确的库路径。
  2. #include在编译中使用的每个文件中使用正确的文件。特别是,不要将#include "matrix.h"与 MATLAB DLL 一起创建的头文件混在一起。
于 2013-01-14T13:09:30.533 回答