有没有办法为 Mac/Windows 制作双重可执行文件? [英] Is there any way to make a dual executable file for Mac/Windows?

查看:43
本文介绍了有没有办法为 Mac/Windows 制作双重可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为 Windows/Mac 制作双重可执行文件的方法.也就是说,我可以在任一操作系统中执行该文件,它会为该操作系统运行一些我想要的代码.此代码可以是脚本或(最好)本地编译的代码,但它需要在 vanilla 操作系统上运行,而无需安装任何额外的工具或库.另一个要求是它必须是单个文件.

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?

推荐答案

我能看到这项工作的唯一方法是安装额外的工具:

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

  • 脚本: Mac(bash shell)和 Windows(有 2 个:PowerShell 和原来的,不知道它的技术名称)之间的命令解析器有很大的不同.您要么必须在 Windows 机器上安装 Unix/Cygwin/Insert-other-UNIXy-Environment 服务,要么使用 perl 或其他脚本语言之类的东西.在任一情况下,至少Windows 机器,可能还有 Mac,需要额外的开箱即用工具.
  • 可执行文件:实现这一目标的唯一方法是使用 Java、.NET/Mono 或其他一些基于字节码的跨平台虚拟机环境.因此,您仍然依赖于非内置工具.(IIRC,Windows 不附带 Java,Mac 不附带 Mono.)
  • 其他问题:在处理工具依赖性后您将遇到的最大问题是两个系统上的路径标识不同.了解 Mac 路径通常是 Unix 风格的路径(尽管我相信老派"Mac 冒号分隔的路径仍然有效).您还必须根据两种环境处理不同的文件位置和默认位置.这会很痛苦.
  • 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.

现在,如果您可以避免使用交叉编译而不是二进制兼容性,那么您可能会在名为 RealBasic.它最初是基于 Mac 的,但也有适用于 Windows 和 Linux 的版本.在这十年的早期,我曾经玩过它,它非常整洁,但不是我专业使用过的东西.这将 如果您小心的话允许您编写一次代码,并编译与本机 Mac、Linux 和 Windows 应用程序完全相同的代码.

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.

这篇关于有没有办法为 Mac/Windows 制作双重可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆