从 DLL 创建符号库以与 MINGW32 一起使用
我正在使用 C++、Qt、Mingw32 和 Netbeans 开发一个工作应用程序。我需要使用公司软件团队开发的内部 API。 我有需要链接的 DLL 的符号库 .lib 文件,但我无法将这些库与 Mingw32 一起使用,它与 Microsoft Visual Studio 一起工作得很好。
有谁知道是否有办法导出符号并创建与 Mingw32 一起使用的 .a 符号库?如果没有,我想我将不得不转向 Visual Studio。
我尝试使用程序“pexports”创建 .def 文件和 dlltool,但这不起作用。仍然出现未引用的符号错误,然后我将它抱怨的符号添加到 .def 中,因为它们不在那里,并且它停止抱怨并编译。但程序崩溃了。我在 Visual Studio 中尝试了相同的代码,它编译并运行良好。
I'm developing an application at work using C++, Qt, Mingw32 and Netbeans. I need to use an in house API that has been developed by the software group in the company.
I have the symbol libraries .lib files for the DLLs i need to link against, but i cannot use these libs with Mingw32, it works fine with Microsoft Visual Studio.
Does anyone know if there is a way to export the symbols and create a .a symbol library that works with Mingw32 ? If not i'll have to go over to Visual Studio i guess.
I have tried using the program "pexports" to create a .def file and dlltool, but that didn't work. Still got unreferenced symbol errors, then i added the symbols it complained about to the .def, because they weren't there and it stopped complaining and compiled. But the program crashes. I tried the same code in Visual Studio and it compiles and runs fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你有没有考虑过动态加载DLL? LoadLibrary、GetProcAddress 等。您可能可以轻松编写一个类,封装所有 DLL 的入口点、加载和卸载库,并执行所有 #typedef 等。这是一项繁重的工作,但如果它是内部库,则可能有入口点不是太多了吗?
导入库被高估了。 :p
Have you considered dynamically loading the DLL? LoadLibrary, GetProcAddress, etc. You can probably easily write a class that encapsulates all the DLL's entry points, loading and unloading the library, and does all the #typedefs, etc. It's grunt work but if it's an in-house library there probably aren't too many entry points?
Import libs are overrated. :p
不确定它是否有帮助,但您可能希望查看本指南。
Not sure if it helps, but you may wish to check this guide.
以下是我对 mysql 库的操作方法。
使用 dllwrap 创建导出列表:
这会在 .def 文件中创建导出列表,但名称修改不正确。
在文本编辑器中编辑 .def 文件并删除“@”符号。
符号名称通常还会附加一个数字。
除了通过实验之外,我不知道如何确定正确的名称:
运行以下命令来创建 netbeans 兼容库:
使用它进行编译,您将获得未定义的符号。未定义的符号将具有正确的装饰。
再次编辑 .def 文件并更正符号名称。重新运行 dlltool 以获取正确的 .a 库文件。
Here's how I did that for the mysql library.
Create a list of exports using dllwrap:
This creates a list of exports in the .def file but the name mangling is incorrect.
Edit the .def file in a text editor and remove the '@' symbols.
The symbol names typically also have a number appended to them as well.
I don't know how to determine the correct name except by experimentation:
Run the following to create a netbeans compatible library:
Compile with it and you'll get undefined symbols. The undefined symbols will have the correct decorations.
Edit the .def file again and correct the symbol names. Re-run dlltool to get the correct .a library file.
您是否尝试过直接链接 DLL,而不是 .a/.lib? MinGW 通常很乐意为您做这件事。
Have you tried linking the DLL directly, rather than a .a/.lib? MinGW is usually happy to do that for you.
我放弃了,有些人说用 c++ 导出在微软编译器上编译的 dll 是不可能的,因为名称重整
I give up, some people say it is not possible with a dll compiled on microsofts compiler with c++ exports, because of the name mangling