Question

I'm looking for a way to make a dual executable file for Windows/Mac. That is, I can execute the file in either OS and it would run some piece of code that I want for that OS. This code can be either a script or (preferably) natively compiled code, but it needs to run on the vanilla OS without needing any extra tools or libraries installed. The other requirement is it needs to be a single file.

Anyone know of a way to do this or is this even possible?

Was it helpful?

Solution

The only way I can see this working is having extra tools installed:

  • Scripts: The command parsers are extremely different between the Mac (bash shell) and Windows (which has 2: PowerShell and the original, don't know its technical name). You'd either have to have Services for Unix/Cygwin/Insert-other-UNIXy-Environment here installed on the Windows box, or use something like perl or another scripting language. In either event, at least the Windows box, and possibly the Mac, need additional out-of-box tools.
  • Executables: The only way you can pull this off is to use Java, .NET/Mono or some other cross-platform bytecode-based virtual machine environment. Hence, you are still dependent on tools which are not in-box. (IIRC, Java doesn't ship with Windows, and Mono doesn't ship with Mac.)
  • Other Issues: The biggest issue you'll run into after dealing with the tool dependency is that paths are identified differently on both systems. Understanding that Mac paths are generally Unix-style paths (although I believe "old-school" Mac colon-separated paths are still valid). You'll also have to deal with different file locations and default locations based on both environments. This will be a pain.

Now, if you can get away with using a cross-compile instead of binary compatibility, you may have an answer in a tool called RealBasic. It was originally Mac-based, but there are versions for Windows and Linux as well. I used to play around with it in the early part of this decade, and it was pretty neat, but not something I ever used professionally. This will, if you're careful, allow you to write the code once, and compile the very same code as native Mac, Linux and Windows applications.

OTHER TIPS

In a script it's all ok, but in a compiled code it will be impossible, because the WIndows executable(exe) is different from the Mac executables(bin) that are different from the Linux executables(whatever you want).

As long as you use a cross-platform language such as Java you can run it on either OS. Native code won't be executable however.

There is nothing similar between the two. No program or script in any language would run exactly the same on both machines without other requirements such as a bash interpreter for Windows for example.

Mono or Java can be installed on a Mac and run programs designed to be cross platform. Without this kind of special library to support multiple platforms there is no common denominator and no way to run the same app on both.

Not exactly what you want, but maybe noteworthy:

You can use Cocotron to compile programs written in Obj-C using Cocoa for Windows. Works pretty well! This won't give you one executable for Mac and Windows, but one for the Mac and one for Windows.

You might want to check out Realbasic. It is a VB clone language with an IDE. It will build executables for Windows, Mac and Linux. realbasic.com

You might consider looking at StarKits which work with Tcl/Tk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top