Running compiled code for linux on windows - go

So I cross-compiled Go code on Windows(10) for Linux and I was actually able to run the same executable on both Windows and Linux how is that possible?

That'd be the new Windows Subsystem for Linux (WSL) that can run Linux ELF binaries natively on Windows 10.

Related

Getting the error: bash: (program): cannot execute binary file: Exec format error, on both 32-bit and 64-bit Windows

There is a program developed for linguistic research (http://people.csail.mit.edu/mcollins/code.html). When I try to run the parser using Git bash terminal on Windows, I get the error:
bash: cannot execute binary file: Exec format error.
First, I assumed it's because of my 64-bit OS, since the file is 32-bit. So, I tried the program on a 32-bit system, but got the same message.
Any ideas on how to fix the issue?:
file (program) shows:
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.2.5, with debug_info, not stripped
uname -srv for my 64-bit OS, shows:
MINGW64_NT-10.0-19042 3.1.7-340.x86_64 2021-03-26 22:17 UTC
uname -srv for my 32-bit OS, shows:
MINGW32_NT-6.1-7601 3.1.7-340.i686 2021-03-26 22:01 UTC
P.S.: If you'd like to give it a try, this code should work in the program directory, but it doesn't work for me:
gunzip -c models/model2/events.gz | code/parser examples/sec23.tagged models/model2/grammar 10000 1 1 1 1 > examples/sec23.model2
As indicated by file, your program is a Linux application so you can't run it on Windows. See
Why does a linux compiled program not work on Windows
Why won't Windows EXE files work on Linux?
Why do you need to recompile C/C++ for each OS?
Mingw is not an environment for running Linux executables, it's just a compiler that compiles POSIX code into native Windows binaries. Neither is Cygwin, which is a reimplementation of POSIX system calls in Windows, and Cygwin binaries are also native Windows binaries with a dependency on Cygwin DLLs. Read this if you want to know their differences. Bash is a shell and isn't a platform to execute files either. Only the runtime platform (OS or something like JVM or .NET CLR VM) can run programs and a shell is just a tool to interact with the OS
So you must run Linux programs in a Linux environment like a Linux machine or WSL1/2. Since the program is 32-bit, you can only run it in Linux or WSL2
Since you have the source code you can also compile the code with mingw or cygwin and run on Windows
Thanks to the answer provided by #phuclv, I realized I need to run the program in Linux. So, I installed 32-bit Linux (I used Linux Mint Debian Edition) on a virtual machine (VirtualBox) on my 64-bit Windows 10, and it worked!

I have generated core-image-minimal on my linux and have installed qemu in windows, how do i run that in windows qemu?

I have generated core-image-minimal on linux, i want to run that on windows qemu.[core-image-minimal files], what is the command to run the image?(in linux i used the command "runqemu core-image-minimal")

Compile MATLAB on Windows for UNIX

I currently have a Unix machine with the MATLAB runtime environment installed and a Windows machine with the MATLAB compiler installed. I can compile and run the standalone successfully on the Windows box, but I cannot determine how to compile from Windows for UNIX.
Is this possible or would I need to compile on the UNIX machine?
This is not possible, you have to compile again on your Unix machine, unfortunately.

How can I package my perl script as a 32-bit executable?

I'm on 64-bit Windows 7 machine, and I've been using PAR:Packager to package my scripts as .exe's.
However, I now need to run these .exe's on a 32-bit Windows 7 machine.
Is there anyway to package it as a 32-bit executable from a 64-bit machine? (is it possible with PAR:Packager?)
You could install a 32-bit perl on your 64-bit machine, but most folks will recommend you just keep a 32-bit VM laying about for those times you need to publish software for legacy machines.

Does Go cross-compile on Ubuntu to a Windows executable?

Using Ubuntu, what steps should I take to compile Go source code into a Windows executable?
Building Windows Go programs on Linux

Resources