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

标签 c++ dllexport

“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/

相关文章:

c++ - 编译器警告 C4251 : Problem exporting a class in a *. dll

通过函数导出的 C++ 插件版本检查

dll - c#dll加密

iphone - Cocoas2d 通过 CGPoint 获取 Sprite

c++ - 二维数组,无法成功填充数据。

C++ 模板。如何让这段代码更漂亮?

c++ - 带有 C++ 的 OS X 中的 SIMD Sony vector 数学库

c# - 为什么我的 dllimport 函数总是返回 true?

c++ - 为什么导出的函数在 DLL 中没有正确命名?

c++ - 使用 boost::spirit::x3 编译错误