C ++如何在def文件中指定名称空间

C++ How to specify namespace in def file

"TestDLL.h"

namespace atest
{
    void HelloWorld();
}

namespace btest
{
    void HelloWorld();
}

我试图通过 def 文件导出 dll 函数。有两个同名的函数,但在不同的命名空间中。我这样写 def 文件:

LIBRARY "TestDLL"
EXPORTS
    HelloWorld @1

visual studio 显示 "error LNK2001: unresolved external symbol HelloWorld"。我找不到有关如何在 def 文件中指定名称空间的任何有用信息。我想知道如何解决这个问题。非常感谢你的帮助。

Def 文件必须包含修饰名称。 (即编译器和 linker 看到的函数名称)

您可以在 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 是 link 对一般修饰名称的文档。