当提供程序仅附带xxx.lib且您使用的是MinGW-w64而不是MSVC时,如何链接到xxx.dll? [英] How to link to an xxx.dll when the provider only ships it with an xxx.lib and you are using MinGW-w64 and not MSVC?

查看:114
本文介绍了当提供程序仅附带xxx.lib且您使用的是MinGW-w64而不是MSVC时,如何链接到xxx.dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebird Boost 社区仅为其预构建的 xxx.dll 二进制文件提供 xxx.lib

Firebird and Boost communities only provide the xxx.lib for their pre-built xxx.dll binaries,

并且我正在将 MinGW-w64 v7.0.0 GCC v8.1.0 一起使用,

and I am using MinGW-w64 v7.0.0 with GCC v8.1.0,

最后一个期望包含所有要链接的 xxx.dll 功能符号的 libxxx.a 文件.

and this last one expects a libxxx.a file containing all the xxx.dll function symbols to link with.

对于 Boost ,我可以从 MinGW-w64 的源代码进行构建(尽管我仍然更喜欢使用预构建的,因为构建过程对于大型这样的工具箱将永远消失).

For Boost, I can build it from the source code for MinGW-w64 (though I still prefer using the pre-built ones, because the build process for big toolkits like this one takes forever).

对于 Firebird ,它根本无法使用 MinGW-w64 构建,除非已修补,并且我不能保证修补后的源文件会产生 fbclient.dll 用于生产.

As for Firebird, it is not buildable using MinGW-w64 at all, except if patched, and I can't guarantee that the patched source files will produce a safe fbclient.dll for production.

我听说 MinGW-w64 的较新版本接受直接链接 .dll

And I have heard that newer versions of MinGW-w64 accept direct linking to a .dll,

这是真的吗?是 MinGW-w64 .dll ,仅 C .dll 或包括 C ++ 的文件,还是任何类型的. dll (包括 MSVC 个).

Is this true? is it just MinGW-w64 .dlls, only C .dlls or including C++ ones, or any kind of a .dll including MSVC ones.

您可能会说:"为什么我不只使用Msys2!?"

  1. Msys2 是一个基于修补程序的软件,我已经看到很多像 libcurl 这样的库,它们仍然不是纯静态的(静态版本.一个(不是 .dll.a 一个)仍然依赖于一个或多个外部 .dll (而不是系统的).
  2. Msys2 是基于 Dwarf2 的异常处理,我正在使用 sjlj .
  3. Msys2 使用了最新的工具链 v9.2.0 和诸如 winpthreads libwinpthread 和< Windows XP ( Windows XP !?是,不再有我的客户仍在使用它)中不再支持的strong> zstd ,所以我必须降级工具链.
  1. Msys2 is a patch based software, and I have seen a lot of libraries like libcurl that are still not purely static (the static version, the .a one not the .dll.a one) still depends on one or more external .dlls (not the system ones).
  2. Msys2 is Dwarf2 based exception handling and I am using the sjlj one.
  3. Msys2 uses a very recent tool-chain v9.2.0 and libraries like winpthreads, libwinpthread and zstd that are no longer supported in Windows XP (Windows XP!? YES, more of my clients are still using it), so I have to downgrade the tool-chain.

那么,在这里链接我有什么选择?

So, what are my options, for linking here?

TIA.

推荐答案

Windows DLL无法与可执行程序链接.对于链接,我们有 为mingw-w64创建一个导出库.该答案假设您已经 在您的开发环境中安装mingw-w64,而mingw-w64工具是 在命令行中可以访问.

Windows DLLs can not be linked with a executable programs. For linking, we have to create a export library for mingw-w64. This answer assumes you have already install mingw-w64 in your development environment and mingw-w64 tools is accessible in command line.

可以从DLL或LIB文件创建导出库.这里的程序是 其次是DLL文件.打开命令提示符.假设DLL是foo.dll.

The export library can be created from DLL or LIB file. Here the procedure is followed from DLL file. Open command prompt. Assume the DLL is foo.dll.

  • 使用gendef生成导出定义文件:
  • Generate Export Definition file with gendef:
gendef.exe foo.dll

此命令使用foo.dll并生成foo.def.

  • 使用dlltool生成导出库:
  • Generate export library with dlltool:
dlltool.exe --dllname foo.dll --input-def foo.def --output-lib libfoo.a

此命令使用foo.deffoo.dll并生成libfoo.a.记住 导出库libfoo.a名称以lib-开头,但在 如果是GCC,则编译/链接的链接选项应为-lfoo. 生成的导出库libfoo.a仅包含以下符号 从DLL导出,因此不能用于静态链接.

This command takes foo.def and foo.dll and generates libfoo.a. Remember the export library libfoo.a name starts with lib- but at the time of compiling/linking the linking option should be -lfoo in case of GCC. The generated export library libfoo.a only contains the symbols that are exported from the DLL, it can not be used for static linking.

该过程不取决于主机是MSYS2还是MinGW-w64或跨主机 任何GNU/Linux发行版中的编译器.

The procedure does not depend if the host is MSYS2 or MinGW-w64 or cross compiler in any GNU/Linux distribution.

  • mingw: How to create an import library for a DLL using MinGW
  • mingw-w64: Generating an import library for a DLL
  • dlltool manpage

这篇关于当提供程序仅附带xxx.lib且您使用的是MinGW-w64而不是MSVC时,如何链接到xxx.dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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