Archived

This topic is now archived and is closed to further replies.

Compilers

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

As I understand it, to develop a game for multiple platforms I would have to move the code over from compiler to compiler to build the platform-specific exes. Which compilers for Windows, Linux and Mac OS X work well together, without too much modifying of source code? How do you program applications for multiple platforms? And just how good is Microsoft Visual C++? Is it by far the best compiler for Windows, or do others compare? [edited by - Shard on November 29, 2003 10:38:13 AM]

Share this post


Link to post
Share on other sites
As long as your code is according to the C++ standard, it 'should' compile on any standard compliant compiler.

The problem usually is platform specific code (creating a window in Windows is different from Linux/OsX etc.), certain libraries that may not be available for every platform, and little/big endian when storing data. And of course, not every compiler is really compliant to all parts of the standard (VC++ 6.0 has some issues for example).

One way is to use #ifdef switches that enable/disable parts of the code, depending on what compiler/platform the sourcecode is compiled.


bool createWindow(...)
{
#ifdef WIN32
//create a Windows window
...

#elif LINUX //Not sure if the constant is called that way...
//create a Linux window
...

#endif
}


Of course you can wrap all this in classes, to provide a nice platform independant interface...

edit: One simple way to make platform independant production easier is to use libraries that work on any platform. The SDL would be an example for such a library. OpenAL (for sound support) would be another. And of course, OpenGL can also be used on most if not all platforms.

[edited by - Wildfire on November 29, 2003 11:12:20 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Wildfire
As long as your code is according to the C++ standard, it should compile on any standard compliant compiler.

The problem usually is platform specific code (creating a window in Windows is different from Linux/OsX etc.), certain libraries that may not be available for every platform, and little/big endian when storing data. And of course, not every compiler is really compliant to all parts of the standard (VC++ 6.0 has some issues for example).

The easiest way is to use #ifdef switches that enable/disable parts of the code, depending on what compiler/platform the sourcecode is compiled.


bool createWindow(...)
{
#ifdef WIN32
//create a Windows window
#elif LINUX //Not sure if the constant is called that way...
//create a Linux window
#endif
}


Of course you can wrap all this in classes, to provide a nice platform independant interface...


Actually, the easiest is to simply use libraries that are available on all platforms. SDL and glut work well for opengl development on linux,windows,mac... openal, and a few other audio libraries work fine. There are plenty of multi-platform libraries available rather than writing it all yourself using #ifdef preprocessors (by the way, it''s called #elseif, not #elif). I did however opt to write my own multi-platform code, I have a base GameSystem class that has a set of variables and virtual functions such as Width, Height, BitDepth, and Initialize(title,width,height,bitdepth,fullscreen), Unload(), Resize(), etc. I currently have 2 classes that inherit this, one linux based, and one windows base. So, it''s as simple as this in my code to switch:

#ifdef WIN32
#define GameSystem OpenGLWinSystem_C
#elseif LINUX
#define GameSystem OpenGLLinuxSystem_C
#endif

I even wrote a DirectXWinSystem_C version for some 2D stuff I was doing, but i don''t normally use that . I use msvc in windows, and well.. gcc under linux .

Share this post


Link to post
Share on other sites
Or use a cross platform library to handle all of that for you - that way all you have to do is to re-compile on the target platform to get the relevant .exe

Share this post


Link to post
Share on other sites
What kind of games are we talking about? If you are going to do a 2d-game, then I would suggesting using the allegro game programming library and gcc. Otherwise there is sdl/opengl and openal as mentioned above. They also compile with gcc.

[edited by - Jolle on November 29, 2003 11:18:32 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Ready4Dis
Actually, the easiest is to simply use libraries that are available on all platforms.


Yes, I was just editing my post when you wrote that.

One thing to look into would be the license each library comes with though... at least in case you plan on selling your product at some point.

Share this post


Link to post
Share on other sites
If you''re going for cross platform I''d personally use the GCC compiler along with SDL and OpenGL (If you''re doing something 3D) GCC is available on many platforms as are SDL and OpenGL so if you code everything properly (not relying on datatypes being certain sizes, byte-order etc) you should be able to compile your game on several different platforms (e.g. Windows, Linux, Mac) without any source modifications.

Share this post


Link to post
Share on other sites
I plan on using cross platform libraries such as SDL to make my code as portable as possible. My concern is with each compiler. I know Visual C++ does not follow standards very well.

Just how much better is it than GCC? If it is far more powerful than other Windows compilers than I will use it, otherwise I could use GCC for all platforms.

Share this post


Link to post
Share on other sites
quote:

Just how much better is it than GCC? If it is far more powerful than other Windows compilers than I will use it, otherwise I could use GCC for all platforms.


I guess it depends a little on what you define as ''a powerful compiler''. Afaik GCC is ''only'' a compiler, whereas Visual C++ includes both a compiler and an IDE. However, to my understanding, there are several very good IDEs you can use in combination with GCC.
The main advantage of using GCC would be that it is the same on all platforms, while Visual is limited to windows. And you get to choose which IDE suits you best .

As far as the compiler itself goes, both offer various levels of code optimization. You''d have to perform a series of benchmarks to see which produces the faster/smaller code. Compile time may also be an issue... maybe you can find some info about that somewhere on the web.

Share this post


Link to post
Share on other sites
I believe the compiler that comes with VC++ .Net can make slightly faster code than GCC. But seeing as VC++ .Net costs a fair amount of money and GCC is completely free it ain''t bad going And if you do want to compile on many different platforms with the same code GCC would probably be your best bet.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> by the way, it''s called #elseif, not #elif
nope, it''s called #elif

Share this post


Link to post
Share on other sites
unless you''re doign something complex with templates, VC++ .NET will compile code with similiar ability as GCC.

Once you start getting into strange template stuff, both GCC and VC++ start doing things wrong.

VC++ 6 does lots of things wrong, and it might cause problems. for instance, the infamous for(int i;;i; problem.

Share this post


Link to post
Share on other sites
I'm going to go with GCC, using the Dev-C++ IDE for Windows and Xcode for Mac. I only have the trial version of MSVC and have been using Dev-C++ so far anyway. I wasn't looking forward to paying for MSVC .

Is there anyway to compile programs for Linux without actually having the OS?

[edited by - Shard on December 1, 2003 12:11:23 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Shard
Is there anyway to compile programs for Linux without actually having the OS?

Yes. GCC can be configured as a cross compiler. You would still need a linux system to test it on, though.

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
quote:
Original post by Shard
As I understand it, to develop a game for multiple platforms I would have to move the code over from compiler to compiler to build the platform-specific exes.

How do you program applications for multiple platforms?



I offten use a simple javac command and then if I expect distribution I use jar xxxxxxx command to create a selfexecutable jar.

I actually found multiple executables as anoying and I like somewhat smaller and more stable bytecode.

quote:

Which compilers for Windows, Linux and Mac OS X work well together, without too much modifying of source code?




When programming for multiple OS you should never expect that your work would be completely done by some miracle compiler.
For example compare XFree and MAC OSX. Actually you should never expect to run executable under windoze without isues.

But for your question is simple answer. Java compiler could do that with less code modifications than other compilers. ~_^

Share this post


Link to post
Share on other sites
quote:

But for your question is simple answer. Java compiler could do that with less code modifications than other compilers. ~_^


Last time I checked Java (VM) was an interpreter, not a compiler? Basically you''re right of course But, excuse my ignorance, I don''t think Java is very suitable for high end games.

Share this post


Link to post
Share on other sites
quote:
Original post by Shard
Yeah, I''m a C++ programmer, not Java.


It''s generally preferrable to be a "programmer" rather than a "C++ programmer" or a "Java programmer".
quote:

How do I set up GCC as a cross compiler?

http://www.mingw.org/mingwfaq.shtml#faq-cross

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
I''ve done a Google search on the cross compile topic. Most pages only deal with Linux -> Windows, the one page that mentions Windows -> Linux says ''requires compiler tweaking'' and ''complicated'' (I recommend reading it, along with subpages).

Also: If you want to test the compiled apps, you''ll need a Linux system. And if you''ve got that it''d be easier to use it for compiling too.

Just as a side note: I''m running a dual boot WinXP/Debian without problems. The Debian system was installed after Windows was on the box, and I use Lilo at boot time to start up the respective system. If you don''t want to go to the trouble of installing a secondary system, you could try out Knoppix which is startable from a CD and should be fairly easy to set up.

Share this post


Link to post
Share on other sites
quote:
Original post by Wildfire
quote:

But for your question is simple answer. Java compiler could do that with less code modifications than other compilers. ~_^


Last time I checked Java (VM) was an interpreter, not a compiler? Basically you''re right of course But, excuse my ignorance, I don''t think Java is very suitable for high end games.


You can call Compiller.disable() from your application and force VM to run in just interpreted mode. Standard behavior is: if it would run more than once - compile it. No binary is writen on HD however, so it might be iteresting to add exe cache to VM. (viruses would be happy. ^_^ )

I tried both and found that Java is less messy and differences aren''t that hight. As long as you aren''t pointer arithmetic maniac.

Shard: "Yeah, I''m a C++ programmer, not Java."

That''s bad, you''d have a lot of problems. Best idea would be win/linux dualboot, but it won''t solve problems with MAC. Be prepared for alot of "a blind programming".
As a sidenote. I know aprox 6 languages and I''m using at least 3-4 regulary. I would recommend anyone to learn more than one language. So he wont be locked in just one.

Share this post


Link to post
Share on other sites