Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

c++ - Can I program for Macs without owning one?

I'm programming a game using C++ and OpenGL/SDL, using Visual Studio as my IDE. I don't own a Mac, nor am I even vaguely familiar with the platform. But I want to release to Mac users all the same.

I have three questions. Can I write and compile Mac programs on a PC? If I can, are there any possible pitfalls to doing so? And finally, can VS2010 compile for Mac, or will I need to use another compiler?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you're using SDL then the answer is "you can get kind of close to your desire, up to the last step, sort of". Being able to write a game-like program in a single codebase, and then take that codebase to various machines and compile it and have it work is exactly what the Simple DirectMedia Library was designed to do! It wouldn't be very popular if it didn't at least make this a reasonable target.

That won't mean you'll be able to push a button and get a Macintosh or Linux binary package out of Visual Studio. But you could always find friends and ask them to try the compilation for you on the codebase. So long as you've been careful to only call functions out of the standard C++ library AND stay inside the box that SDL gives you, it should compile fine...in theory.

Update 2018: - If you want to compile on Mac and don't have one, Travis-CI now has virtualized OS X, so you can run clang and actually have it upload the resulting binaries somewhere. You probably don't want to wait for a full build over the network each time you make a change...but once you get a cross-platform codebase building on OS X, continuous integration can make sure you keep it that way.

It can be harder in C++ than it is in other languages to make sure you're staying within a "portability sandbox" (especially if you're a beginner). And it can be harder if you're following tutorials targeting Microsoft tools especially, as they have few qualms about advising you to make Windows-only calls in their documentation. So the odds of being able to hand the "fully debugged" code to a friend, have it compile and work on a new platform the first time will be low.

You'll need a testing period, certainly. And you probably shouldn't wait until the last minute to have someone else make sure the basics are working by compiling it in XCode or whatever. You can lower the risk of writing nonportable code by using the GCC compiler instead, which will be more likely to complain if you start bringing in dependencies that are not actually cross platform.

It also may be possible to run a "Hackintosh" virtual machine if you like living on the edge. You can certainly make a Linux VM and try building under that, and if it works that will raise the confidence that a Mac build will work too. Won't guarantee it though.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...