0

我正在使用其他人使用 c++ 和 matlab 开发的程序。我有两者的源代码,但我不知道发生了什么......

Matlab 使用类似这样的方法调用从 c++ 生成的 dll:

myCustomCppFunction('param1', 'param2)

我期待在 dll 导出中看到myCustomCppFunction,但我找不到它。

当我运行dumpbin命令时,我收到如下信息:

dumpbin /exports c:/myCustomCpp.dll
ordinal hint RVA      name
1    0 00001010 myCustomCppFunctionWithADifferentName

所以,

myCustomCppFunctionWithADifferentName != myCustomCppFunction

DLL 导出的函数名称与我的 matlab 调用的函数名称不同。而且我不是在谈论混乱的名字,两个名字都是 100% 不同的,比如“苹果”和“香蕉”。:-)

不知何故,一切正常!但是如何?!?

在 Matlab 中,我还运行了哪个命令向我确认调用的函数来自我正在调查的 DLL....

>> which myCustomCppFunctionWithADifferentName
>> c:/myCustomCpp.dll

任何线索?

4

1 回答 1

1

除了你的标签,我不确定你在处理 MEX 文件。

MEX 文件(DLL)的名称与导出函数的名称无关。MEX 文件中的导出函数为:

mexFunction

在 Windows 中,仍然有DLLMain,但MATLAB 会查找mexFunction.

所以这就是发生的事情:

>> myMEXFunction()  % looks for myMEXFunction.mexw64 (or whatever extension)

如果 myMEXFunction.mexw64 已mexFunction导出,则说明您在做生意。

请注意,声明mexFunction(如果您正在编译 .cpp),您只需在源代码中定义它。所以它总是没有装饰。mex.hextern "C"

但是,您的 myCustomCpp.dll 没有 export mexFunction,所以也许您不是在谈论 MEX 文件?此外,如果您在谈论 MEX 文件,让我更加不确定的是您使用which. 您的 MATLAB 源代码 ( myCustomCppFunction) 是否实际使用loadlibrarycalllib与 DLL 一起操作?如果myCustomCppFunction()以这种方式加载了非 MEX DLL,那么您所显示的内容是有意义的。

于 2015-07-20T22:08:50.387 回答