C++ – How to develop a cross-platform C++ project

ccmakecross platformkdevelopvisual studio 2012

I'm a C++ beginner and I'm starting to develop my first cross-platform C++ project. I need to use platform-specific calls (Win32 and POSIX) so I need to compile frequently both in Windows and Linux.

Whit single-platform projects I'm using, until now, KDevelop in Linux and Visual Studio 2012 in Windows.

How can I use two different IDEs in two different Operating Systems with the same project?

  1. Should I use a single, cross-platform, IDE?
  2. Should I learn CMake (or similar) and configure it to work with both IDEs?
  3. Could/Should I host my code in the web and sync automatically with offline projects?
  4. Alternatives?

Thanks in advance to everyone.

EDIT:

Just for clarification, the project will be a simple server for a scholastic protocol. There will be a client asking for upload/retrieve some files to/from the server.
With scholastic I mean that, for example, I have to use pthreads/win32 threads instead of an higher level C++ threads library.

Best Answer

  1. Maybe - really depends on what you feel most comfortable with. As the project is non-graphical, all the IDE gives you is editing of files and compilation. So you can build the project on one machine with the IDE there, and then move the sources to another machine for compiling there.

  2. I personally would just have two makefiles, one for Linux and one for Widnows. Makes life fairly simple [you could have a "outer" makefile that picks the right one based on some clever method].

  3. Yes, you should find a version control system that works for both Windows and Linux (git, mercurial, subversion, bazaar and several others). That way, not only do you have a central repository [you can use either of your machines as "server" for any of these], but it also allows you to keep track of your changes. Definitely worthwile doing!

  4. There are hundreds of different alternatives. But the simpler you keep it, and the less complicated your tools are, the more time you get to spend on actually programming your project, rather than, for example, figure out why CMake isn't building the way you want it to.

Also, make sure that you separate out all your system-specific code to one file per architecture. That way, it's easy to port to another architecture later, and it makes MOST of your code compile on both systems.