Jump to content
  • Advertisement

Archived

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

Rebooted

Compilers

This topic is 5432 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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!