Visual C ++ - 链接插件DLL对EXE? [英] Visual C++ - Linking plugin DLL against EXE?

查看:175
本文介绍了Visual C ++ - 链接插件DLL对EXE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个大型C ++应用程序从Linux(gcc)移植到Windows(Visual C ++ 2008),并且有插件的链接器问题。在Linux上这不是一个问题,因为.so支持运行时符号查找,但dll似乎不支持这个。

I'm in the process of porting a large C++ application from Linux (gcc) to Windows (Visual C++ 2008) and am having linker issues with plugins. On Linux this wasn't an issue, as .so supports runtime symbol lookup, but dll does not seem to support this.

一些背景信息:
托管脚本环境的应用程序(主机)为插件(通过脚本API调用在运行时加载的共享库)提供接口,从而允许扩展主机和脚本API,而无需重新编译主机应用程序。在Linux上这只是一个问题,包括主机应用程序的头部在插件源,但在Windows上我收到链接器错误。我不确定是否需要链接到Visual C ++来解析这些符号。

Some background information: The application (the host), which hosts a scripting environment, provides interfaces to plugins (shared libraries that are loaded at runtime by script API calls), allowing the host and the scripting API to be extended without recompiling the host application. On Linux this is just a matter of including the host application's headers in the plugin source, but on Windows I'm receiving linker errors. I'm not sure exactly what I need to link with for Visual C++ to resolve these symbols.

我们的一个依赖项(开源,LGPL)有预处理器声明用于在其头部中插入__declspec(dllexport)和__declspec(dllimport)。一些以前的研究表明,我可能必须这样做,但我想确定在我去修改一大堆核心标题。 (我以前能够在MinGW上工作,但是我们决定支持Visual Studio是这种商业项目的一个要求。)

One of our dependencies (open source, LGPL) has preprocessor declarations that it uses to insert __declspec(dllexport) and __declspec(dllimport) into it's headers. Some prior research indicates that I may have to do this as well, but I'd like to be sure before I go modifying a whole bunch of core headers. (I was previously able to get this working on MinGW, but we've decided that supporting Visual Studio is a requirement for this sort of commercial project.)

我的问题, 如何在Visual C ++中将运行时加载的dll与主机exe链接?

编辑:例如,我在我的主机应用程序中有一个类对象,它表示可以由脚本访问的对象的基本类型。在我的插件中,我有一些类扩展对象执行其他功能,如集成网络支持或新的视觉元素。这意味着我的dll必须链接到主机exe中的符号,我不知道该怎么做。

To clarify the problem with an example, I have a class in my host application, Object, which represents the base type of an object that may be accessed by a script. In my plugins I have a number of classes which extend Object to perform other functions, such as integrating networking support or new visual elements. This means that my dll must link with symbols in the host exe, and I am not sure how to do that.

推荐答案

你是说运行时符号查找吗?是指使用 dlopen dlsym 等等? Windows 中的等效项名为 LoadLibrary GetProcAddress

What do you mean by "runtime symbol lookup"? Do you mean dynamically loading libraries using dlopen and dlsym and so on? The equivalents in Windows are called LoadLibrary and GetProcAddress.

在Windows中,不从可执行文件导出符号。你应该只从dll导出它们。解决你的问题的正确方法是rearchitect,以便导出的符号在一个DLL,可执行文件和其他插件DLL可以链接。

In windows, you don't export symbols from a executable. You should only export them from a dll. The right way to solve your problem is to rearchitect so that the exported symbols are in a dll that the executable and other plugin dlls can link against.

这篇关于Visual C ++ - 链接插件DLL对EXE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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