Thread: Is there anyway that I can compile my code on Windows but it runs on Mac computers?

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    55

    Is there anyway that I can compile my code on Windows but it runs on Mac computers?

    So the thing is that we're using Macs on a class, but I only have a Windows PC, and my assignments need to run on these Macs...

    Is there any windows compiler or something that lets me run my C++ programs on Mac?

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I had posed the same question to a programmer friend of mine when I was thinking about making some apps for the iphone/ipod ect. He suggested downloading a VM and setting up a compiler in it. I'm sure there are drawbacks to this as I'm not very knowledgable on the subject, but it could at least get the ball rolling for you.

    Virtual machine - Wikipedia, the free encyclopedia

    Though I'm sure one the the senior programmers here has a better solution.
    Last edited by Lesshardtofind; 09-18-2010 at 01:35 PM.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85
    Make sure you write portable code. Also, try to use the maximum warning settings in your compiler, so that your teacher's compiler doesn't spit out errors that you could've prevented.

    This implies that you DO NOT, under any circumstance, use OS specific APIs.

    Edit: Of course, you can use OS specific APIs if you #ifdef a valid alternative, but for simple things the standard should be good enough for you.
    Last edited by Jorl17; 09-18-2010 at 02:57 PM.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    55
    yeah, the problem is that I don't own a mac though, so I can't compile the mac version of my code

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Unix operating systems can use Wine, a program that can execute Windows and MS-DOS binaries, as long as they use a command-line interface or a simple GUI.

    WineHQ - Run Windows applications on Linux, BSD, Solaris and Mac OS X

  6. #6
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85
    Quote Originally Posted by thefeedinghand View Post
    yeah, the problem is that I don't own a mac though, so I can't compile the mac version of my code
    Then follow my logic: Write portable code. If it's portable and fully standards compliant, it __HAS__ to compile. If it doesn't, then it's the implementation/compiler's fault and you should not be penalized.

    You just have to make sure that you do it. Alternatively, as suggested, you can compile Windows binaries and ask your teacher to use Wine with it. I hang around Wine's forum a lot and I can tell you that it is really good.

    But stick with portable and standards compliant code. Don't fall into common pitfalls such as defining arrays with non-const size_t's and the like...

    And, to make sure that it is compliant, enable maximum conformance / warnings in your compiler.

  7. #7
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Are you expected to turn in program source code or compiled executables? If you only need to turn in the source code then simply write portable (i.e. conforming strictly to the language standard and avoiding platform-specific APIs) programs, as Jorl has already said.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  2. How Can I compile 3 source code in 1 program ?
    By lord_cedrich in forum C Programming
    Replies: 8
    Last Post: 12-10-2006, 05:10 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 02:58 AM