9 Replies Latest reply: Aug 10, 2013 4:48 AM by MrHoffman
isiah1018 Level 1 (0 points)

I compiled c++ code in xCode and the program works fine.


To send it to another mac, i zipped the file, emailed it, and the other mac was able to open the zip and run the file no problem.


But how do I send it to a PC?


I tried emailing the file the same way as prev stated, then changing the extension FROM the PC to .exe and opening it with command prompt but I get "illegal action" error message.



Is there a way I can share my C++ program that runs in Terminal on my Mac, with a PC?

If so, how do I get it to run on the PC.


Thanks, Isiah.

  • xnav Level 5 (6,635 points)

    A C++ executable is not portable between Mac and PC.  You might be able to recompile the source on the PC and get it to work.

  • MrHoffman Level 6 (14,750 points)

    Most traditional programming languages and most compiled applications incorporate dependencies on the host operating system, make various calls to the host operating system, and even use data structures and formats within the executable file itself that are host-specific; executables are generally not portable. 


    This is the case across Microsoft Windows, Linux, OS X, Unix, OpenVMS, HP-UX, Tru64 Unix, Solaris, *BSD, and most any other operating system around.


    Most compilers — including C and C++, and Objective-C and Objective-C++ — do not generate portable executables.


    There are sometimes translation tools available that can allow the code to invoke the expected host operating system features on another platform (that's not the target operating system platform), but I'm aware of no tool for this particular porting situation.  An example of this approach is Wine, which allows some Windows executables to operate on Linux.  Again, there's no tool available to do this from OS X to Microsoft Windows AFAIK.


    Programming environments involving an interpreter such as Python, Lua, Java and Ruby — there are various other languages here, and the distinction between compiled and interpreter can be a little murky — generally can be packaged and transported and invoked on another target platform, so long as the dependencies are available on the target platform.  OS X includes Python and Ruby, and Java and Lua are available.


    Xcode can be used to maintain and build portable applications, but that's usually done with a command-line build or a build script (for Unix and Linux platforms), or using a tool such as make to sequence the compilation and linking.  Xcode can invoke those scripts, but those are created manually, and Xcode needs to be told to call the particular scripts and not its default build procedures.


    Porting and software portability are complex topics.

  • Michael Black Level 7 (20,377 points)

    There are open source C compilers for Windows (e.g. mingw, Microsoft Visual C++ express, Orange C).  Try one of those on the windows machine with your source code.

  • isiah1018 Level 1 (0 points)

    thank you so much for the detailed explanation. I understand completely now. Greatly, greatly appreciated.


    Can you please explain the last paragraph about Xcode? What's the point you are trying to make about XCode, I'm a little bit confused upon your last paragraph.


    Thanks, greatly appreciated,



  • isiah1018 Level 1 (0 points)

    I realize that this is the only other way to get the program to run on a PC. I was more concerned on the possibility of portability of the executable.


    Thanks for your help, nonetheless.



  • MrHoffman Level 6 (14,750 points)

    The Xcode documentation is probably your best resource for learning the tools.  Here's the Xcode user's guide (which doesn't cover using makefiles, but does introduce the tool) and here's a porting-related document in the Xcode documentation set, and look also around for what's called an "external build system" (In Xcode 4.6.3, see the doc for File > New > New Target > OS X, Other > External Build System) as well as the man pages for make and mkdep and probably a few other tools. 


    Beyond the Xcode documentation, if you're a member of the Apple developer programs, the developer forums and other developer resources and videos are a good resource for learning and for researching these sorts of questions.  There's also the Xcode mailing list.  There have been various discussions of connecting make and Xcode around the 'net, and probably in the mailing list archives, as well.

  • isiah1018 Level 1 (0 points)

    thank you so much!

  • rccharles Level 5 (7,574 points)

    Michael Black wrote:


    There are open source C compilers for Windows (e.g. mingw, Microsoft Visual C++ express, Orange C).  Try one of those on the windows machine with your source code.

    What about gcc?



    Isn't gcc what xtool is using for the C++ compiler?  Best to use the same compiler in all environments.



  • MrHoffman Level 6 (14,750 points)

    rccharles wrote:


    Isn't gcc what xtool is using for the C++ compiler?  Best to use the same compiler in all environments.


    On OS X, any current Xcode version installs the llvm-clang chain including the lldb debugger, when the command-line tools are selected.


    The llvm compiler chain replaced gcc on OS X within Xcode for both C and C++ a while back, and gcc was deprecated.


    Having worked with both chains, I prefer clang to gcc for both for its integration with Xcode, and for its diagnostics.  I found lldb a bit rough early on, but it's working nicely now.


    Clang is available on various platforms beyond OS X, including Windows: Clang - Getting Started.