views:

539

answers:

7

I am starting an open source cross platform project in C++. My development environment is Linux. There may be other developers who develop from different platforms as well. So I need some help in getting started with the configuration and development environment setup, so that all developers from multiple platforms can develop easily.

Following are my questions

  1. Compiler : I plan to use g++ and heard that it is cross platform. Is that a good choice?
  2. Make files : I have seen Code::Blocks editor and it generates make files on fly and you don't have to write one manually. Is this the best practice or do I need to create make files?
  3. What are the other settings to be taken care when developing cross-platform applications?

Any thoughts?

Edit

Thanks for the answers. One more question.

Do you create makefiles by hand? Or is there any tool which can generate it?

+1  A: 

Compiler : I plan to use g++ and heard that it is cross platform. Is that a good choice?

Yes, but which version? Do you have a list of known issues for the version you are going to use?

Make files : I have seen Code::Blocks editor and it generates make files on fly and you don't have to write one manually. Is this the best practice or do I need to create make files?

A classical choice. You probably will need to tweak them when the project grows.

What are the other settings to be taken care when developing cross-platform applications?

A g++/makefile port is available for ever major platform. So, once you have made sure you are not using any platform specific API or construct you should be good to go.

What about the following?

  • 3rd party libraries? Make sure you don't fall for a platform specific one.
  • Licensing issues (your code and others)
  • SCM
dirkgently
I have latest version of G++. Installed using package manager in ubuntu.
Appu
I really don't need to know, but you should :) Just make sure you note down the versions of the tools you are using. Can save a lot of grief in the coming days.
dirkgently
+1  A: 

Here is a book to answer all your questions. Cross-Platform Development in C++: Building Mac OS X, Linux, and Windows Applications

Nikhil
Good suggestion. I will get a copy of it.
Appu
+2  A: 

Depending on the specific platforms, Qt may hold the answers. Especially with the new license.

Ryan Graham
Qt and qmake. I also recommend it over wxWidgets, which is propagated by CodeBlocks.
ypnos
+2  A: 
  • Start building on multiple platforms now: it exposes issues early on.
  • If you only care about Linux and Mac OS X, then g++ should be just fine. There are various IDEs and build systems available. You might want to consider using autotools to help out with configuration support.
  • If you want to target Windows, it gets a bit more complicated. You can use cygwin and/or mingw, but that can be complicated sometimes. Various projects use cross-platform build and configuration systems like CMake to take care of many issues for them.
Mr Fooz
+4  A: 

The most important thing for your project to catch up is portability. It should be easy to build & run for everybody.

GCC (g++) is indeed the compiler of choice. It comes from the opensource world and is therefore most widely adopted by it.

However, a simple Makefile won't cut it. Generating it using CodeBlocks or any other IDE has a problem: Due to their platform, other developers will probably have to generate their own, but won't necessarily have CodeBlocks at hand, or just don't want to use it.

There exist several different cross-platform build systems, which are IDE-agnostic. Some of them create Makefiles, others don't use make but build on their own.

  • The most widely adopted build system is Autotools. However, it is hard to learn, cluttered, and an overall pain in the ass.
  • Out of many other choices, I recommend Waf. It is proven by several larger open source projects already, XMMS2 being a good example (while not a very popular project, it has a large build with a lot of plugins and builds on a lot of platforms including OS X and Windows). While waf is not very broadly adopted, it is meant to be shipped with the source and easy to set-up. My recommendation for you.

Edit: to get started with your Open Source project, I also recommending this book by Karl Fogel (available for reading online). Have fun!

ypnos
Thanks for the answer.
Appu
see also my edit.
ypnos
+1  A: 
Martin
+2  A: 

The GNU C++ compiler is a relatively good choice for crossplatform work, except that on Windows only a relatively old version (3.4) is natively supported. Work is underway to port a 4.x-series to Windows, but so far it's not ready for prime time.

Rather than focus on what compiler to use, I'd instead focus on which language to use. Writing ANSI standard C++ will go a long way towards making your code crossplatform. As far as possible, hide platform-specific behavior behind a good toolkit, such as Qt.

For cross-platform build environments, this may depend on what toolkit you use. Qt has QMake, which is relatively good. CMake is another compelling choice. I would avoid Autotools, since it has very poor portability outside of UNIX -- using Autotools on Win32 is very often the torment of the damned.

Finally, start working on multiple platforms now. VMware is invaluable for something like this. Get your code to compile on Linux, on FreeBSD and on Windows. If you can hit those three targets, moving to other platforms will be enormously easier in the future.