从DLL导出静态的lib符号 [英] Exporting static lib symbols from DLL

查看:105
本文介绍了从DLL导出静态的lib符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Facade DLL到一个静态的lib。 Dll提供了一个小型接口和资源管理,可以跨多个DLL共享。 Dll-Header会从静态库中泄露东西:

  class DLL_EXPORT MyDllClass {
public:
/// ...
OneStaticLibClass * ptr;
};

问题是:如果这样工作,我必须链接 StaticLib 到DLL和应用程序使用DL​​L。我没有正确地导出 StaticLib 的部分。我在导出标题中尝试过:

  class DLL_EXPORT OneStaticLibClass; 

但这不行...我还是得到:

 未定义的引用到OneStaticLibClass ::〜OneStaticLibClass(void)
未定义的引用到OneStaticLibClass :: operator<(char const *)

Andy想法如何使用DLL导出部分静态库?



谢谢!

解决方案

您将需要创建一个.def文件并将其传递给链接器。在这种情况下,DLLEXPORT不是必需的。



原因是使用静态库时符号被解析。创建DLL时,仅搜索DLL本身所需的符号,并将包含这些符号的对象文件复制到DLL中。如果DLL代码不引用您的析构函数,则不会包含它。



.def文件将告诉链接器哪些函数被导出。导出的函数将从静态库中进行搜索和拉出。



此过程的一个缺点是您需要在.def文件中使用被破坏的C ++名称。可以使用dumpbin实用程序获取Mangled名称。


I'm using a Facade DLL to a static lib. The Dll provides a small interface and resource management to be shared across multiple DLLs. The Dll-Header do expose stuff from the static library:

class DLL_EXPORT MyDllClass {
public:
   /// ...
   OneStaticLibClass * ptr;
};

The Problem is: if this should works I've to link the StaticLib to the DLL and the application using DLL. I didn't manage to export parts of the StaticLib correctly. I tried in the export headers:

class DLL_EXPORT OneStaticLibClass;

but that doesn't work... I still get:

undefined reference to OneStaticLibClass::~OneStaticLibClass(void)
undefined reference to OneStaticLibClass::operator<<(char const *)

Andy ideas how I can export parts of the static library with the DLL?

Thank you!

解决方案

You will need to create a .def file and pass it to the linker. DLLEXPORT is not necessary in this case.

The reason for this is the way symbols are resolved when using a static library. When you create a DLL, only those symbols needed by the DLL itself are searched, and object files containing these symbols are copied into the DLL. If the DLL code does not reference your destructor, it will not be included.

A .def file will tell the linker which functions are exported. Exported functions will be searched and pulled from the static library.

One downside of this process is that you need to use mangled C++ names in the .def file. Mangled names can be obtained with the dumpbin utility.

这篇关于从DLL导出静态的lib符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆