我正在使用其他人使用 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 中,我还运行了 which 命令,它向我确认调用的函数来 self 正在调查的 DLL....
>> which myCustomCppFunctionWithADifferentName
>> c:/myCustomCpp.dll
有什么线索吗?
最佳答案
除了你的 mex标记,我不确定您处理的是 MEX 文件。
MEX 文件(DLL)的名称与导出函数的名称无关。 MEX 文件中导出的函数是:
mexFunction
在 Windows 中,仍然有一个 DLLMain
,但是 MATLAB 寻找 mexFunction
。
这就是发生的事情:
>> myMEXFunction() % looks for myMEXFunction.mexw64 (or whatever extension)
如果 myMEXFunction.mexw64 导出了 mexFunction
,则说明您在做生意。
请注意,mexFunction
在 mex.h
中声明为 extern "C"
(如果您正在编译a .cpp),您只需在源代码中定义它。所以它永远是未修饰的。
但是,您的 myCustomCpp.dll 不导出 mexFunction
,所以您可能不是在谈论 MEX 文件?此外,如果您在谈论 MEX 文件,让我更加不确定的是您使用 which
得到的奇怪结果。您的 MATLAB 源代码 (myCustomCppFunction
) 是否实际使用 loadlibrary
或 calllib
来操作 DLL?如果 myCustomCppFunction()
以这种方式加载了一个非 MEX DLL,那么您显示的内容就有意义了。
关于c++ - 不同于导出的 DLL 函数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460778/