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

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

问题描述

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



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



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



我的问题是,简单来说:如何在Visual C ++中链接运行时加载的DLL与主机exe?



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

解决方案

你的意思是运行时符号查找?您是否意味着使用 dlopen dlsym 等等 Windows中的等效版本称为 LoadLibrary GetProcAddress



在Windows中,不导出符号从可执行文件。您应该只从dll导出它们。解决问题的正确方法是重新构建,以便导出的符号在可执行文件和其他插件dll可以链接的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.

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.

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.)

My question, in a nutshell: How do I link runtime-loaded dlls against a host exe in Visual C++?

Edit: 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.

解决方案

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.

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天全站免登陆