在Cygwin下链接到带有GCC的Windows .dll + .lib文件组合? [英] Link against a Windows .dll+.lib file combination with GCC under Cygwin?

查看:187
本文介绍了在Cygwin下链接到带有GCC的Windows .dll + .lib文件组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在Unix-ish上下文中链接库:如果我正在使用 .a .so 文件,我用 -L / my / path / to / lib / 指定根搜索目录,对于libMylib,我添加 -lMyLib

I know how to link against libraries in Unix-ish contexts: If I'm working with .a or .so files, I specify the root search directory with -L/my/path/to/lib/ and for libMylib I add -lMyLib.

但是如果我有


  • a 怎么办? dll (例如在 Windows\System32 目录中)?

  • a .dll (在 Windows\System32 中)和 .lib (在其他地方) ?

  • a .dll (e.g. in the Windows\System32 directory)?
  • a .dll (in Windows\System32) and a .lib (someplace else)?

这些DLL是由另一方提供的;我无权访问其源代码-但可以访问我设法针对其编译的相应包含文件。

These DLLs are by some other party; I don't have access to their sources - but do have access to the corresponding include files, against which I manage to compile.

推荐答案

如果您可以链接到Cygwin或MinGW中的 .lib ,则可以(间接)链接到DLL。

If you can link against a .lib in Cygwin or MinGW, then you can (indirectly) link against a DLL.

在MSVC世界中,创建导入库和DLL并不少见。这是一个静态库( .lib ),它加载DLL并包装DLL的接口。您只需在(静态)导入库中调用包装函数,然后让导入库执行所有与DLL相关的操作。

In the MSVC world, it is not unusual to create an import library along with a DLL. It is a static library (.lib) that loads the DLL and wraps the interface of the DLL. You just call the wrapper functions in the (static) import library and let the import library do all the DLL-related things.


  • 对于Windows API,WindowsSDK中有导入库。

  • 对于您自己的MSVC DLL,MSVC可以在生成DLL时自动生成导入库。

  • 对于第三方DLL,您可以基于相应的头文件来构建静态包装库。

.lib 文件中的链接Cygwin或MinGW是可能的。示例:

Linking against the .lib file in Cygwin or MinGW is possible. Example:

g++ -o myprg myprg.o -lShlwapi

此链接指向Shlwapi.lib。 (该库必须位于本地目录中或链接程序的库路径中。)

This links against Shlwapi.lib. (The library must be in the local directory or in the library path of the linker.)

与DLL导入库的链接相同。

Linking against import libraries of DLLs works the same way.

注1:请记住不同的ABI和名称修饰。但是,在大多数情况下,可以在DLL或LIB文件中调用纯C函数。

Note 1: Keep in mind the different ABIs and name mangeling. However, calling plain C functions in DLL or LIB files will work in most cases.

注2:请记住,g ++要求以正确的顺序指定库

Note 2: Keep in mind that g++ requires the libraries to be specified in the correct order.

这篇关于在Cygwin下链接到带有GCC的Windows .dll + .lib文件组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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