views:

62

answers:

3

Hello, everyone...

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.

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.

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.

thanks

A: 

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

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 temp and/or word-writable locations, if you need to).

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).

dirkgently
I'm using what xcode terms "command line tool," which builds c++ specifically.No images, sounds etc.I'm on Leopard OS, and wasn't expecting to run into trouble in trying to build a console program to be universal. And yes, I've tried building a universal binary. Hope this gives enough context. Thanks for the help- this is useful stuff.
NBG
A: 

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:

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!

btown
No, no- that's helpful. Although, I think my question is phrased improperly; or at least it's incomplete. Maybe I should ask it this way:Do you know whether it is possible for me to compile a simple text-based (no graphics, sounds, etc.) c++ game to be cross-platform compatible; specifically, do you know how/if xcode can compile and build a product to be run anywhere there is a console?I realize my question may be ill-informed. Thanks so much for your informative responses.
NBG
If by cross-platform you mean on both Mac and Windows, then no—Xcode doesn't have a compiler for non-Mac executables. But it should definitely be possible to cross-compile for different versions of Mac OS X.
John Calsbeek
If you really need to be able to build for Mac, Windows, and Linux from Xcode, then Xcode has "custom build steps" that can run any command line script. You can then use a cross-compiler toolchain that runs from a command line. See, for instance, http://lilypond.org/gub/ (although that's definitely overkill and may not even work on Macs, it's just to show that it's possible). My advice? Find a Windows and/or Linux machine, copy your C++ files over, and compile for Windows/Linux separately. You can test your code in Xcode though. Good luck!
btown
A: 

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.

JWWalker
Tried that, initially. Sending through Yahoo, it produces a "text file" every time. I've tried renaming, alternative builds (deployment, release), to no avail.Yes, I've only written the command line tool version thus far. No graphics, sounds, etc.; only the code including standard headers.Thanks for your timely response. Really appreciate the help, here.
NBG