Mac OS question

This is a discussion on Mac OS question within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I'm sure this answer is obviously to the point of trivial to some, but I looked around a ...

  1. #1
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118

    Mac OS question

    Hi everyone,

    I'm sure this answer is obviously to the point of trivial to some, but I looked around a bit and couldn't find a suitable answer. ^_^

    My C++ compiler produces a .exe file. Someone told me that they couldn't run one of my programs as they were using a mac which couldn't open .exe files. So what type of file would a mac C++ programmer produce, and would they work on PCs?

    Thanks in advance for any replies,

    Kind Regards

    Stonehambey

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    Quote Originally Posted by Stonehambey View Post
    Hi everyone,

    I'm sure this answer is obviously to the point of trivial to some, but I looked around a bit and couldn't find a suitable answer. ^_^

    My C++ compiler produces a .exe file. Someone told me that they couldn't run one of my programs as they were using a mac which couldn't open .exe files. So what type of file would a mac C++ programmer produce, and would they work on PCs?

    Thanks in advance for any replies,

    Kind Regards

    Stonehambey
    .app

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    If you want a C++ program to work on a mac, you have to compile it on a Mac or with a compiler that creates an executable that runs on the mac OS you are targeting. Just changing the extension won't help.

  4. #4
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    I ask simply because I'm probably going to be buying a new laptop when I start my postgrad course next year and am weighing up the pros and cons of buying a mac over a pc. Since C++ has become one of the more prominant uses for my current laptop I wouldn't want anything to get in the way of that

    If I create a .app file using a mac, will it run on a pc? I sometimes put programs on my site and want it to reach as many people as possible.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    When you're learning C++, you generally write code and copy the code to your different machines as necessary. If you write portable code (which most C++ learners should), then while you're on the Mac you can compile it into something that runs on Mac. Then you can copy the code to a PC and compile it on the PC for something that runs on the PC.

    Mac OS X runs a Unix style system, and it might even have the gcc compiler installed already, so you shouldn't have any trouble writing code for it.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Just to clarify: the extension of the file is not really what matters here. That's only making it easy for us humans to recognize the type of the file. [1]

    What happens, however, is that the different OS makers come up with different ways to store the executable file. The file contains (essentially) identical code in itself, but the data that the OS uses to tell how large the code is, how large the data section is, what DLL's or .so files (Unix/Linux/MacOS X corresponding to DLL's) this particular executable file relies on, etc, etc, is what changes [and of course, if the machines have different processors, then the code itself will also be different, but nowadays Mac's use the same type of processor as PC's].

    [1] Yes, windows still uses the extension to recognize if the file can be executed or not, but you can actually add for example .app to the list of executable extensions, should you wish.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    In a nutshell: if you write portable code, then you should be able to compile it under Mac and Windows, generate executables specific to a platform, and run it under that platform. However, compiling it under one system and running it in another isn't going to work very well.

    On the other hand, it can be useful to compile for different platforms on one system. For example, on my Linux system I can use wine to generate a Windows executable. I can also emulate Mac OS 7 (which is ancient), though I've never really gotten anything to compile there. (Supposedly MPW works. I've gotten it to work on a native Mac OS 9 system, but not OS 7.)

    I have no idea how difficult it would be to create Windows executables from a Mac or vise versa. Probably quite difficult. You'd likely have to have two different machines or some emulation software of some sort.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    16

    Bootcamp

    You can even use BootCamp with your Mac, install a minimal version of Windows just for compiling and creating executables, and you are done in *native* environment.

  9. #9
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    If you want compile-once-run-everywhere, try Java.

    C++ is at best write-once-compile-everywhere currently.

  10. #10
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    Thanks for the replies guys. Based on these answers I think I will forgo the mac for the moment. I can't really justify paying 3 times what I would for a pc with the same specs. I've never really been one to buy into apple's smug image

    Quote Originally Posted by cyberfish
    If you want compile-once-run-everywhere, try Java.

    C++ is at best write-once-compile-everywhere currently.
    I've already fallen for C++ I'm afraid. Besides, isn't Java write-once-debug-everywhere?

    Cheers,

    Stonehambey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mac OS X aliases
    By rak1986 in forum C Programming
    Replies: 4
    Last Post: 01-21-2009, 11:11 AM
  2. C++ OS X question
    By Nectarios in forum C++ Programming
    Replies: 6
    Last Post: 01-04-2009, 07:30 PM
  3. Mac backup software
    By brewbuck in forum Tech Board
    Replies: 2
    Last Post: 08-12-2008, 08:21 PM
  4. .NET Runtime on Linux / Mac OS
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 05:46 AM
  5. question from linux board ( not os dependant )
    By crypto in forum C Programming
    Replies: 4
    Last Post: 11-15-2002, 01:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21