How to Convert a Linux Executable File (Binary) to Windows Exe File

Convert a Windows .exe file into the binary contents

You can use xxd to view binary or hexadecimal dumps

for binary

xxd -b {_file_}.exe

To get the output of this command inside a .txt file

xxd -b {_file_.exe} > {_file_}.txt

How to pack files into one executable file for Linux and Windows?

The honest answer would be: "With great difficulty, lots of pain, blood and tears."

The somewhat longer answer is, that a precompiled DLL/.so may contain slightly more than a mere static library. It it possible to "convert" a DLL/.so into a static library? Somewhat. It boils down to dumping its contents into object files, reverting all the relocation entries, possibly dealing with versioned symbols and weak symbols. No, there are no kitchen sink utilities out there, doing all that for you on an executable binary level.

If you can limit yourself to Linux, you may want to look into Flatpak. What this does is wrapping everything up into a sort of "self extracting archive", which upon launch will transparently and invisibly unpack itself into an in-situ temporary mount point (which you won't see from the rest of the system).

Now, one option would be to build all the dependencies of your program yourself, and arranging for those builds to be created as static libraries. In that case you're no longer dealing with DLLs. However some libraries do not want to be built for static linking, so your mileage may vary there.


Truth to be told: Why is distributing multiple files any issue at all? On Linux/*BSD you must ship separate icon and .desktop files anyway, so that stuff shows up in the Desktop application menus. Yes, it'd be nice if instead of dealing with XDG desktop entry files we had the option to place all of that information into a special – let's call it .xdgdata – readonly section, with some well known symbol names, so that we could have truly single file distributable executables.


My honest suggestion: Don't sweat about it. Just ship the whole bunch of files and don't worry too much about "how this looks".

How to compile executable for Windows with GCC with Linux Subsystem?

Linux Subsystem works as a Linux-computer. You can only run Linux executables inside it and default gcc creates Linux executables.

To create Windows executables, you need to install mingw cross-compiler:

sudo apt-get install mingw-w64

Then you can create 32-bit Windows executable with:

i686-w64-mingw32-gcc -o main32.exe main.c

And 64-bit Windows executable with:

x86_64-w64-mingw32-gcc -o main64.exe main.c

Note that these Windows executables will not work inside Linux Subsystem, only outside of it.



Related Topics



Leave a reply



Submit