#### Archived

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

# 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.

## 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 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 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 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 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 on other sites
quote:
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 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 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 on other sites
Visual studio c++ 6 doesn''t follow standards well, the 2003 version does do so very well.

##### 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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632930
• Total Posts
3009290
• ### Who's Online (See full list)

There are no registered users currently online

×