“TestDLL.h”
namespace atest
{
void HelloWorld();
}
namespace btest
{
void HelloWorld();
}
我试图通过def文件导出dll函数。有两个函数具有相同的名称,但位于不同的命名空间中。我这样编写 def 文件:
LIBRARY "TestDLL"
EXPORTS
HelloWorld @1
Visual Studio 显示“错误LNK2001:无法解析的外部符号HelloWorld”。我找不到有关如何在 def 文件中指定 namespace 的任何有用信息。我想知道如何解决这个问题。我将非常感谢您的帮助。
最佳答案
Def 文件必须包含修饰名称。 (即编译器和链接器看到的函数名称)
您可以在 Microsoft's site 上阅读详细信息,但这是相关部分:
If you are exporting functions in a C++ file, you have to either place the decorated names in the .def file or define your exported functions with standard C linkage by using extern "C". If you need to place the decorated names in the .def file, you can obtain them by using the DUMPBIN tool or by using the linker /MAP option
就我个人而言,我更喜欢使用/MAP
。我发现它比使用 DUMPBIN 那样的瑞士军刀要简单得多。
供引用here是一般修饰名称文档的链接。
关于C++ 如何在 def 文件中指定命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45788838/