DLL中的外部符号解析 [英] External symbol resolving in a dll

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

问题描述

我正在使用插件系统进行跨平台的c ++/qt项目,我们正在Linux上使用so文件,在Windows上使用dll.通过cmake,我们在Linux上使用gcc,在Windows上使用Visual Studio 2010.问题是我们的插件有时需要从应用程序源代码调用一个函数,在Linux上使用gcc时,只要包含头文件,该函数就可以正常工作.但是在Visual Studio上,我们遇到了无法解决的外部符号错误.

I'm working on a cross-platform c++/qt project with a plugin system, we are using so files on linux and dll on windows. We are using gcc on Linux and Visual Studio 2010 on Windows through cmake. The problem is our plugins sometimes need to call a function from the application source code, which is working fine on Linux with gcc by just including the header files. But on Visual Studio, we got unresolved external symbol errors.

是不是因为dll文件和dll文件的工作原理不同?

Is it because so and dll files works differently?

谢谢.

推荐答案

在Windows上从dll导出符号的默认行为是完全相反的:默认情况下,符号是不可见的,您需要显式导出它们.使用VC ++,这是通过 __ declspec(dllexport) 声明符.

The default behaviour for exporting symbols from dlls on Windows is exactly opposite: by default, symbols are invisible, you need to export them explicitly. With VC++ this is done by __declspec(dllexport) declarators.

EDIT(添加了信息):您正在输入一个非标准化的,系统特定的行为区域...用C ++编写跨平台的可插拔"组件系统存在的问题比您预期的要多得多.在Windows上,有所谓的导入库,它定义了从dll导出的所有符号.您必须链接这些库才能解析这些符号.这称为隐式链接.您还可以显式链接,这意味着在运行时加载dll及其导出的符号.但是,与所谓的二进制兼容性问题相比,所有这些都只是技术细节,即使在组件系统的设计中没有考虑,这几乎肯定会杀死您.

EDIT (Information added): You are entering a region of non-standardized, system specific behaviour... There are much more problems associated with writing cross-platform "pluggable" component systems in C++ than you might be expecting. On Windows there are so called import libraries, which define all symbols exported from a dll. You have to link against these libraries in order to resolve these symbols. This is called implicit linking. You can also link explicitly which means loading dll and its exported symbols at run-time. However all these are just technical details compared to so called binary compatibility issues, which will almost certainly kill you, if not considered during the design of your component system.

我想知道一件事:您说您正在使用Qt.Qt应用程序框架拥有自己的跨平台约定和规则,用于编写和构建可插拔组件.你为什么不坚持这些……?

I am wondering about one thing: You said you're using Qt. Qt application framework has got it's own cross platform conventions and rules for writing and building pluggable components. Why don't you stick with these...?

这篇关于DLL中的外部符号解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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