简体   繁体   English

从DLL创建符号库以与MINGW32一起使用

[英]Create symbol libraries from DLLs for use with MINGW32

I'm developing an application at work using C++, Qt, Mingw32 and Netbeans. 我正在使用C ++,Qt,Mingw32和Netbeans开发工作中的应用程序。 I need to use an in house API that has been developed by the software group in the company. 我需要使用由公司软件组开发的内部API。 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. 我有需要链接的DLL的符号库.lib文件,但是我不能将这些库与Mingw32一起使用,它可以与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 ? 有谁知道是否可以导出符号并创建与Mingw32一起使用的.a符号库? If not i'll have to go over to Visual Studio i guess. 如果没有的话,我想我必须去Visual Studio。

I have tried using the program "pexports" to create a .def file and dlltool, but that didn't work. 我尝试使用程序“ pexports”创建一个.def文件和dlltool,但是没有用。 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. 仍然存在未引用的符号错误,然后我将其抱怨的符号添加到.def,因为它们不存在,并且不再抱怨并编译了。 But the program crashes. 但是程序崩溃了。 I tried the same code in Visual Studio and it compiles and runs fine. 我在Visual Studio中尝试了相同的代码,并且可以编译并正常运行。

Have you considered dynamically loading the DLL? 您是否考虑过动态加载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? LoadLibrary,GetProcAddress等。您可能可以轻松编写一个类,该类封装所有DLL的入口点,加载和卸载库以及执行所有的#typedef等。这很麻烦,但如果是内部库,则可能没有入口点不是太多吗?

Import libs are overrated. 导入库被高估了。 :p :p

不确定是否有帮助,但是您可能希望查看本指南

Here's how I did that for the mysql library. 这是我为mysql库所做的操作。

Create a list of exports using dllwrap: 使用dllwrap创建导出列表:

dllwrap --export-all-symbols --output-def libmysql.def libmysql.dll --implib liblibmysql.a

This creates a list of exports in the .def file but the name mangling is incorrect. 这将在.def文件中创建导出列表,但是名称处理不正确。 Edit the .def file in a text editor and remove the '@' symbols. 在文本编辑器中编辑.def文件,然后删除“ @”符号。 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: 运行以下命令以创建与netbeans兼容的库:

dlltool --input-def libmySQL.def --dllname libmySQL.dll --output-lib libMySQLclient.a -k

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. 再次编辑.def文件并更正符号名称。 Re-run dlltool to get the correct .a library file. 重新运行dlltool以获取正确的.a库文件。

Have you tried linking the DLL directly, rather than a .a/.lib? 您是否尝试过直接链接DLL,而不是.a / .lib? MinGW is usually happy to do that for you. MinGW通常很乐意为您这样做。

我放弃了,有人说由于名字改错,不可能在Microsofts编译器上使用C ++导出来编译dll。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM