为 mingw 编译 linux 库

发布于 2024-10-08 20:41:15 字数 193 浏览 3 评论 0原文

我一直在使用 C++ 的套接字库。其他一些信息:32 位 Linux、Codelite 和 GCC 工具集。我希望能够使用 Windows 版本的 Codelite 为 Windows 编译我的程序。我一直在使用的套接字库没有 mingw32 版本的库,但它是开源的。那么我怎样才能构建 mingw32 的套接字库,以便我可以使用提供的源代码进行 Windows 构建呢?

I have been using a socket library for C++. Some other info: 32 bit Linux, Codelite and GCC toolset. I want to be able to compile my program for Windows using the windows edition of Codelite. The socket library I have been using doesn’t have a mingw32 build of the library, but it’s open source. So how can I make a mingw32 build of the socket library so I can make a windows build using the source provided?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

快乐很简单 2024-10-15 20:41:15

大多数开源 Linux 库都是使用 make 构建系统构建的(尽管还有其他一些库,例如 jam 等,以及用于构建的自定义编写脚本)。 MinGW 附带了 make 实用程序,它是 mingw32-make.exe。 (如果您幸运的话)可以通过在 Windows 上创建库来简单地重建您的库。

更常见的情况是,您需要先配置项目,然后才能构建它。 Windows shell 不支持配置所需的脚本要求,但 MinGW 项目的另一部分(称为 MSYS)确实支持。如果您安装了 msys 及其所需的所有必需工具,您将能够在运行 make 之前 ./configure 您的项目。

当然,只有当库被编写为可移植时,上述方法才有效。 Linux 套接字实现 (sys/socket.h) 和 Windows 实现 (winsock2.h) 之间存在一些重大差异。您可能被迫编辑代码块,以确保其版本针对平台正确(或者所需的任何依赖项也是针对 Windows 构建的)。

此外,该库可能已经为 Windows 构建,但使用不同的编译器(例如 MSVC),它生成 .lib 和 .dll 文件。 Mingw 需要 .a 文件作为库,但一个聪明的功能是能够直接链接到 .dll,而不需要导入库,因此您通常可以使用不是针对 Mingw 构建的现有 Windows 库(尽管这赢得了对静态链接没有帮助)。还有一个工具dlltool,可以将.lib转换为.a。

如果您提供有关您正在使用的特定库的详细信息,我也许可以为您找出在 Win 上运行它需要做什么。

Most open source linux libraries are built with the make build system (although there others like jam etc, and custom written scripts for building). MinGW comes with the make utility, it's mingw32-make.exe. It may be possible (if you're lucky) to simply rebuild your library by making it on Windows.

The more usual scenario is that you will need to configure the project before you can build it though. The windows shell doesn't support the scripting requirements required to configure, but there's another part of the MinGW project that does called MSYS. If you install msys and all the required tools you need for it, you'll be able to ./configure your project before running make.

Of course, the above will only work if the library is written to be portable. There are some breaking difference between the linux socket implementation (sys/socket.h), and the windows implementation (winsock2.h). You may be forced to edit chunks of the code to ensure that it is versioned correctly for the platform (or that any dependencies required are also built for Windows).

Also, there is the chance that the library may already be built for Windows, but using a different compiler like MSVC, which produces .lib and .dll files. Mingw requires .a files for libraries, but a clever feature is the ability to link directly against a .dll, without the need for an imports library, so you can often use an existing windows library that was not built against Mingw (Although this won't help for static linking). There is also a tool, dlltool, which can convert .lib to .a.

If you give detail on the specific library you're working with, I may be able to pick out for you what needs to be done to run it on Win.

自在安然 2024-10-15 20:41:15

您将其移植到新平台。 :)

你很幸运它是开源的,因为那样的话几乎不可能移植它(你必须支付 $$$ 才能获得特定许可证的代码副本,或者重写整个产品)。

享受。

或者,他们很可能已经有一个端口...检查您正在使用的库的文档。

You port it to the new platform. :)

You're fortunate that it is opensource, because then it would be practically impossible to port it (You'd have to pay $$$'s to get a copy of the code for a particular license, or rewrite the entire product).

Enjoy.

Alternatively, they may well already have a port... Check the documentation for the library you are using.

洛阳烟雨空心柳 2024-10-15 20:41:15

首先,您需要确保没有包含任何 Linux 特定的库。

First off your going to need to make sure that you aren't including any Linux specific libraries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文