Hello. The title probably speaks for itself. Is it possible?
Background
I’m developing a pretty simple CLI application translating a binary file to its text description and vice versa. I want it to be portable, so a compiled language is needed (no Perl or Ruby). It will be mostly used by Windows users.
What I have already written, is written in Rust. However, I’m not used to it (I’m not a professional programmer at all), it has its peculiarities and is quite low-level. I want to switch to something at a little higher level. Go doesn’t appeal to me for some reason, but Crystal does.
Creating a ready-to-use Windows executable that just works (under Wine) for a Rust program on Linux has been quite simple. However, I don’t know how to do it for a Crystal “hello world” program without using a Windows instance.
Previous efforts
The resources I found on the Internet pointed out the --cross-compile
option, so I tried
crystal build main.cr --cross-compile --target x86_64-pc-win32
but this method doesn’t perform the linking process, it just tells me what command to run on a Window box and I have none (at least not a modern one).
Someone on the Internet mentioned MinGW. I don’t know how to use it, so I just tried
x86_64-w64-mingw32-gcc main.obj -o main.exe
but it produced a lot of undefined reference
errors.
At this point I visited the Crystal Discord “server”. Where I explained the issue and asked for help, re:fi.64 tried to help me and after some digging (including downloading the Windows release of Crystal and extracting its libraries) I ended up with
LC_ALL=C x86_64-w64-mingw32-gcc main.obj -o main.exe -L win-lib -lgc -lpcre2-8 -liconv -ldbghelp
but this command didn’t work either, giving over 30 Warning: corrupt .drectve at end of def file
(sic) and even more undefined reference
.
(Nevertheless, huge thanks to re:fi.64 for trying to help!)
End
Thus, I ask the question in this open forum. Is it possible to easily cross-compile and “cross-link” a Windows executable on Linux? If it is, how to do that?
Kind regards.