I compiled a C++ program under Linux:
make -f mymakefile
This will generate an executable,
a.out. It seems this executable cannot be run in the Windows command prompt.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
You cannot natively run a program for Linux under Windows. They are completely different operating systems.
However, there are methods you can try to run the program:
Granted, depending on the nature of the program and its dependencies, it might not be possible to run in another environment without additional software, modifications to the source code, or at all.
You need the Linux subsystem for Windows (WSL) and a Linux distribution. The Windows store has a few Linux distributions prepackaged with WSL. Ubuntu is fairly popular, but since you already have a Linux system on which you built
a.out, it might be easiest to match that.
If you can't match the Linux distributions, and
a.out doesn't work as-built, it's also possible to re-run
make on your WSL distribution
The answer above covered most of the aspects, but not sure if have come across flinux (sometimes called foreign linux) which happens to have been also suggested here and may be an easier workaround depending on what you are trying to achieve.
(Note I have WSL and work with emulators and VMs a lot, and I haven't really explorer other workarounds :))
Foreign LINUX is a dynamic binary translator and a Linux system call interface emulator for the Windows platform. It is capable of running unmodified Linux binaries on Windows without any drivers or modifications to the system. This provides another way of running Linux applications under Windows in constrast to Cygwin and other tools. It now runs a large bunch of console applications and some GUI applications.
You can cross compile for Windows on Linux.
This allows you to use Linux to compile a binary executable program that runs under Windows.
Another option which is similar to running a Virtual machine, but not exactly the same is running your application from a Docker container.
Yes Docker for Windows uses a VM in the background (MobyLinuxVM on HyperV), but you can do something like this:
$ docker run a.out
and will stop the container on its own. It will also use less resources and the output can be read from Windows own terminals like cmd and PowerShell.
A dockerfile for this situation will look something like this:
FROM docker pull ubuntu:latest RUN make -f mymakefile
I think personally this is the nicest solution for running Linux applications in Windows
Try to get the windows exe or msi equivalent of the linux executable and run or use cygwin to install linux executable.
There is a tool mobaxterm very helpful, have a look and you can get your task done. This tool has cygwin and other linux utility to proceed with.