Run a linux executable on windows - linux

I got an executable file created with linux. I also have the files and libraries that created this exe linux file.
Two questions:
Is there a way to run this linux exe in windows or it has to be done with linux?
The files are from around 15 to 18 years ago. If can't run it from windows, would linux be able to run it even if the files are somewhat old?
Could someone advice? Thanks

You can use WSL available on Windows 10 and 11.
You can also setup a Linux virtual machine using Virtual Box, Hyper-V, VMware Workstation Player, or any other virtualization solution, copy your files to the VM and execute there.
Another option is to install and use Docker. With docker you could run a command like this: docker run -it --rm -v $PATH_TO_EXE_DIRECTORY:/app ubuntu:latest /app/name_of_your_exe from command line.
Will it actually run if it's old? Your mileage may vary. It depends if it's a statically linked executable or dynamically linked executable. Statically linked executable may run, or may complain about incompatible kernel version (I've seen it once). Dynamically linked executable may fail to run due to missing dependent libraries or incompatible versions.
To check if the file is dynamically linked you can use Linux file command file name_of_your_exe, it will print the information regarding the data in the file, including whether it's dynamically or statically linked. To investigate the dependencies you can use Linux command ldd name_of_your_exe which will print the list of libraries (.so extension per Linux convention) your executable is dependent upon.
Your best option to ensure that it will run is to try and figure out which Linux distribution and version it was intended for and find its VM image or installation media online (it should still be possible, IMO), setup a VM and try to run it there.

Related

How to generate an executable file that can run both on macOS and Linux

I generate an executable file on macOS and now I want to run it on Linux.
I already have my Makefile and I use that to make the executable file on macOS(using gcc). But when I run it on Linux, I got an error message: "./executable: cannot execute binary file". Can anyone help me with solving this problem?
You will have to compile the executable again on Linux in order to create a binary that runs on Linux.
Unless you setup a cross-compile environment for Linux on MacOSX (using Linux in a Virtual Machine will be easier though), then you could compile for Linux there.
Either way you will end up with 2 different binaries. You can't create a single binary that will run on both Linux and MacOSX.

How to run ELF binary file on cygwin

I'm new to cygwin but I am having a bit of a trouble.
I have Linux ELF compiled binary file, and is there a way to lunch it under cygwin a simple way, like windows binary for example .\a.exe
from https://www.cygwin.com/
Cygwin is not:
a way to run native Linux apps on Windows. You must rebuild your
application from source if you want it to run on Windows.
If you want to run a ELF binary you need a VM with Linux inside

How do I open the root.disk in linux?

When doing a wubi install of linux from windows, the place/file where all linux info is saved is inside a "root.disk" file.
I am intending on formatting my laptop to run linux only and I can't seem to find a way to open this root.disk file from linux itself (to extract some of the files from my previous installation). Of course, it does and is able to open in windows using a certain software, but because I will only have linux on my system now, does anybody know how to open this file in linux itself? It's kind of strange that it isn't able to open with the default linux tools.
Specs:
I am using Linux Mint 12 (via wubi install). Intending on moving to a 'lighter' version of linux.
You need to mount this image before you can access it, try the following:
mkdir olddisk
sudo mount -o loop /path/to/root.disk olddisk
You should now be able to access the data inside this container.

Generating Xcode build on linux machine using GCC

i have gcc installed on my linux machine and i have my xcode project on my linux machine.
now is there anyway i can generate a xcodebuild using gcc on linux machine?
Very unlikely - the project file is designed for the sole use of Xcode and its command line friends. You are better off creating a Makefile for use under Non-Mac systems; this will be much quicker that trying to determine how the Xcode project file is structured and how to use the information contained within it.

Emulating Linux binaries under Mac OS X

How do I run Linux binaries under Mac OS X?
Googling around I found a couple of emulators but none for running Linux binaries on a Mac. There are quite a few posts about running Mac OS X on Linux and that kind of stuff - but that's the opposite of what I want to do.
Update:
Thanks for all the answers! I am fully aware of MacPorts and Fink or any of the other things; and no, I do not want any of these utilities, and I do not want any of the package managers, I prefer to compile things myself. I also have Parallels and could set up virtual machines and all that jazz...
The only thing I want to do is to find a way to run a binary that I do not have the source code for and has been compiled for Linux, but I do not want to run it under Linux but under Mac OS X. Therefore my question about emulators.
Well there is a project introducing something like Linux's binfmt_misc to OS X so now what you need is an ELF loader, a dynamic linker that can load both Mach-O and ELF, and some mechanism to translate Linux calls to OS X ones.
Just for inspiration, you can implement the dynamic linker in the fashion that it ignores filename extension - both libfoo.so.1 (as an Linux ELF) and libfoo.1.dylib (as an Mach-O) can be loaded so that OS X versions of system libraries can be reused so that you do not need to write a "hosted on OS X" libc.so and syscalls can be handled by an kext that translates Linux calls to OS X ones in kernel.
Or, in an more elegant way, implement a stripped down Linux kernel as a kext that makes the OS X kernel a dual-purpose. However that will require you to use two sets of libraries. (Binaries do not clash so it is largely okay)
Set up a virtual machine (I personally use VMWare Fusion) and then install whatever distro of Linux you desire on the virtual machine.
Or, if you have the source to the Linux program, chances are you can recompile it on a Mac and run it natively. If you install Fink or MacPorts, you can install a lot of open source programs without much trouble.
I recently found Noah, which you can use to run Linux binaries on macOS. You can install Noah via homebrew (brew install linux-noah/noah/noah). Then you should be able to do this:
noah linux_binary
In my experience the behavior of the binary matches what I see on my Ubuntu machine.
You might have some luck with running Linux executables under Mac OS X using Qemu's User Space Emulator
If you decide to go the virtualization route, consider also VirtualBox.
Also, if you only need UNIX like command line tools, there is the MacPorts project. This is basically how I set up git on my mac: after having installed MacPorts you just have to run the sudo port install git command to install git on your system.
noah does not allow the binaries to execute properly for me. Use Docker Desktop for Mac.
Just do:
docker pull centos:latest # 73MB CentOS docker image
Make a folder for what is needed to run your binary, and in your Dockerfile:
FROM centos
COPY your_binary /bin/
ENTRYPOINT ["your_binary"]
and you can build it with
docker build -t image_name
then execute with
docker run image_name as if it were the binary itself. Worked for me. Hope it helps someone else. And if you need specific outputs or to store files somewhere you can mount volumes onto the docker with -v, for example:
docker run -v path_to_my_stuff:/docker_stuff image_name,
though adding a WORKDIR /docker_stuff line to the Dockerfile before ENTRYPOINT is probably best.
If you change ENTRYPOINT to
ENTRYPOINT ["bash", "-c"]
and add
CMD ["your_binary"]
underneath it, you can actually pass the command into the image like
docker run -v path_on_local:/in_container_path image_name "your_binary some_parameters -optionrequiringzerowhitespacebeforeinputvalue"

Resources