xcode 的 c++ 项目的可执行产品

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3596138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:41:08  来源:igfitidea点击:

xcode's executable product for c++ project

c++xcodeuniversal

提问by NBG

I've completed a simple numbers-version of the game "Towers of Hanoi" using xcode's command line tool in C++. Being accustomed to PC compilers like borland's and visual-c, I've attempted to "share" the game with others via e-mail by simply attaching the executable product built by xcode. However, the recipients can't run the program as it shows up in a different format - usually machine code, it sounds like.

我已经使用 xcode 的 C++ 命令行工具完成了游戏“河内之塔”的简单数字版本。习惯了像 borland's 和 visual-c 这样的 PC 编译器,我试图通过简单地附加由 xcode 构建的可执行产品通过电子邮件与其他人“共享”游戏。但是,收件人无法运行该程序,因为它以不同的格式显示 - 通常是机器代码,听起来像。

After a bit of extensive searching, I'm realizing the complexity of building projects within xcode's IDE and the variations on the build settings/ targets, etc.

经过一些广泛的搜索,我意识到在 xcode 的 IDE 中构建项目的复杂性以及构建设置/目标等的变化。

Anyone know how to build a self-contained c++ executable to be universally run? I don't go outside the STL library for this game. I'd greatly appreciate any help.

任何人都知道如何构建一个自包含的 C++ 可执行文件以普遍运行?我不会为了这个游戏走出 STL 库。我将不胜感激任何帮助。

thanks

谢谢

回答by btown

OS X is based on Unix, which uses plain binary files (i.e. no filename extension) as executables. If they have a certain "executable permission," they can be double-clicked to be run as executables, or run from the command line. However, this permission can't be sent over email - it's metadata within the file system itself, and this makes sense from a security standpoint (you wouldn't want spammers sending you executable viruses over email right?). So when the recipient receives the binary, they'll need to run the following command line command on it, assuming "hanoi" is the name of the binary file:

OS X 基于 Unix,它使用纯二进制文件(即没有文件扩展名)作为可执行文件。如果它们具有一定的“可执行权限”,则可以双击它们以作为可执行文件运行,或者从命令行运行。但是,此权限不能通过电子邮件发送 - 它是文件系统本身中的元数据,从安全角度来看这是有道理的(您不希望垃圾邮件发送者通过电子邮件向您发送可执行病毒吗?)。因此,当收件人收到二进制文件时,他们需要在其上运行以下命令行命令,假设“hanoi”是二进制文件的名称:

chmod +x /path/to/hanoi

If you really want to package it as an instantly double-clickable application, you'll need to give it a native UI and package it as a .app, then put that .app (which is actually a folder with the .app extension) in an archive to distribute. Sorry if that's more work than you were hoping for. Hope this helps!

如果你真的想把它打包成一个可以立即双击的应用程序,你需要给它一个原生的 UI 并将它打包成一个 .app,然后把那个 .app (它实际上是一个带有 .app 扩展名的文件夹)在要分发的存档中。抱歉,如果这比您希望的工作多。希望这可以帮助!

回答by JWWalker

If you're satisfied with a command line tool rather than a double-clickable app, it should suffice to zip it and attach that to the e-mail. Be sure to build universal if anyone you're sending to might be using a PowerPC-based Mac. Oh, and set the deployment target to the minimum OS that any recipient might be using.

如果您对命令行工具而不是可双击的应用程序感到满意,那么将其压缩并将其附加到电子邮件中就足够了。如果您发送给的任何人可能正在使用基于 PowerPC 的 Mac,请确保构建通用。哦,并将部署目标设置为任何收件人可能使用的最低操作系统。

回答by dirkgently

Sharing applications across dot releases of the same OS can be notoriously difficult on the Mac (at least, as far as personal experience goes).

在 Mac 上,在同一操作系统的 dot 版本之间共享应用程序是出了名的困难(至少,就个人经验而言)。

In order to be able to share your application with the least amount of effort, you will need to figure out:

为了能够以最少的努力共享您的应用程序,您需要弄清楚:

  • What project type is this? Are you using any resources like images etc?
  • What version of the OS your friends are using? If they are not on the Mac, you're out of luck (or you'll have to recompile for their OS-es).
  • If they run Mac, check out that you have the same OS versions, if you have developed on Leopard and someone's running on SnowLeopard your application might simply fail. (I also ran into issues between Mac OS 10.5.4 and 10.5.3 so keep your fingers crossed.)
  • Check out what sort of hardware you are running. Are you building for your hardware (say, MacIntel) only or are you creating an Universal Binary?
  • Make sure that all resources are packaged into your application bundle. Make sure your application uses only relative paths.
  • Check if you are not writing to special folders (i.e. use only tempand/or word-writable locations, if you need to).
  • 这是什么项目类型?您是否使用任何资源,如图像等?
  • 你朋友用的是什么版本的操作系统?如果它们不在 Mac 上,那么您就不走运了(或者您必须为它们的操作系统重新编译)。
  • 如果他们运行 Mac,请检查您是否具有相同的操作系统版本,如果您在 Leopard 上开发并且有人在 SnowLeopard 上运行,您的应用程序可能会失败。(我还遇到了 Mac OS 10.5.4 和 10.5.3 之间的问题,所以请保持手指交叉。)
  • 检查您正在运行的硬件类型。您是仅为您的硬件(例如 MacIntel)构建还是创建通用二进制文件?
  • 确保所有资源都打包到您的应用程序包中。确保您的应用程序仅使用相对路径。
  • 检查您是否没有写入特殊文件夹(即temp,如果需要,仅使用和/或可写字的位置)。

I wish I could give a more detailed/to the point reply but unfortunately you'll have to figure out some of the answers yourself (without any other specific information about the error you are getting).

我希望我能给出更详细的/重点答复,但不幸的是,您必须自己找出一些答案(没有任何其他关于您得到的错误的具体信息)。