用Cygwin编译独立的exe [英] Compile stand alone exe with Cygwin

查看:316
本文介绍了用Cygwin编译独立的exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用cygwin做一个独立的exe。我有两个选项:


  1. 静态链接cygwin1.dll

    如果我可以静态链接cygwin1.dll然后我可以得到一个独立的exe。


  2. 将cygwin1.dll与myprog.exe合并

    如果我可以将cygwin1.dll与我的程序合并,我可以得到一个立场单独的exe


不建议我使用IlMerge。这不会工作,因为我没有使用.NET编译我的程序。



这些选项是否有可能?如果没有,有什么可能的这个困境吗? Thanx!

解决方案

我可以看到你认为合理的两种可能性。一个是使用不同的编译器构建存根可执行程序(例如,MinGW - 无论如何,不​​需要cygwin)将主可执行文件和cygwin.dll解压缩到临时目录中,然后生成该可执行文件。要仅分发单个可执行文件,您需要将主可执行文件和cygwin.dll添加到stub作为二进制资源。这是一个有点丑陋,但非常简单。



替代方法是抓住 source to cygwin ,并将其构建为静态库。至少从理论上讲,这应该是更清洁的 - 但这也是更多的工作。将其构建为纯静态代码而不是DLL将几乎肯定会采取一些工作,虽然很难甚至猜测多少。只是浏览一下,这似乎不太可能是几个小时的快速工作,或任何类似的东西(除非有一些我错过的东西,已经支持静态构建,当然)。


I want to make a stand-alone exe with cygwin. I have two options:

  1. Staticly link cygwin1.dll
    If I can statically link cygwin1.dll, then I can get a stand-alone exe.

  2. Merge cygwin1.dll with myprog.exe
    If I can merge cygwin1.dll with my program, the I can get a stand-alone exe.

Do not suggest that I use IlMerge. This will not work because I didn't compile my program with .NET.

Are any of these options possible? If not, is there anything that is possible with this dilemma? Thanx!

解决方案

I can see two possibilities that you might consider reasonable. One would be to build a stub executable with a different compiler (e.g., MinGW -- whatever, just so it doesn't need cygwin) to unpack the main executable and cygwin.dll into a temporary directory, and then spawn that executable. To distribute only a single executable, you'd want to add the main executable and cygwin.dll to the "stub" as binary resources. It's a bit ugly, but pretty straightforward.

The alternative would be to grab the source to cygwin, and build it as a static library. At least in theory, this should be cleaner -- but it's also undoubtedly more work. Getting it to build as purely static code instead of a DLL will almost certainly take some work, though it's hard to even guess how much. Just browsing a bit, it's seems pretty unlikely that it's going to be a quick job of a couple hours, or anything like that (unless there's something there that I missed that already supports building it statically, of course).

这篇关于用Cygwin编译独立的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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