Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile stand alone exe with Cygwin

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!

like image 551
Leo Izen Avatar asked Sep 03 '10 22:09

Leo Izen


People also ask

Can Cygwin compile for Windows?

To compile and run SU2 in Cygwin on a Windows machine, you will need to configure Cygwin with the appropriate packages (listed below), and then continue from within Cygwin as though you were using a linux machine. In summary, the steps are: Download Cygwin installer.

Is Cygwin a compiler?

The 64 bit Cygwin compilers use a different data model than the Mingw and Microsoft compilers. For reference, see the Wikipedia entry on 64-bit computing. While the Mingw and Microsoft compilers use the LLP64 data model, Cygwin compilers use the LP64 data model, just like Linux.

What does Cygwin include?

Cygwin consists of a library that implements the POSIX system call API in terms of Windows system calls to enable running of a large number of application programs equivalent to those on Unix systems, and a GNU development toolchain (including GCC and GDB) to allow software development.

Which version of Cygwin?

The most recent version of the Cygwin DLL is 3.3.6. The Cygwin DLL currently works with all recent, commercially released x86_64 versions of Windows, starting with Windows Vista.


3 Answers

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).

like image 175
Jerry Coffin Avatar answered Nov 06 '22 05:11

Jerry Coffin


Try passing -mno-cygwin as a compiler and linker flag. If your program's requirements are simple enough this will avoid depending on Cygwin libraries and create a standalone EXE.

like image 45
Edmund Avatar answered Nov 06 '22 04:11

Edmund


More precise answer of Jerry.

Procedure described below should be confronted with your rights and license law! I know it can work but rights to distribute the result (or even perform the procedure) may be (and I'm really feel that are) bounded by Cygwin license. That is because your application will still refer to Cygwin (even though it is useless - but is still in your app)

Assume hello.exe is the name of your great application compiled under Cygwin in great project directory C:\xxx\yyy\zzz\

In the cygwin console go to C:\xxx\yyy\zzz and type

objdump -p hello.exe | grep "DLL Name"

You obtain all DLLs your application uses. Then copy C:\xxx\yyy\zzz to all DLLs listed and specific for cygwin.

Note that your application may invoke other applications (using exec function for example) --- find libraries aplications use and copy this libraries as well as this applications themselves -- to C:\xxx\yyy\zzz.

Maybe you will have to recompile your project with option of kind -L C:\xxx\yyy\zzz or so. Watch all other paths in your sources.

Thus your application becomes independent of Cygwin installation and you can present its functionality to/ share it with ---- other Windows users without Cygwin. But - once more I point and ask you - be aware of proper license and law of Cygwin creators and observe them!

like image 39
dtstgseete Avatar answered Nov 06 '22 05:11

dtstgseete