Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneous C++ development on Linux and Windows

We have a handful of developers working on a non-commercial (read: just for fun) cross-platform C++ project. We've already identified all the cross-platform libraries we'll need. However, some of our developers prefer to use Microsoft Visual C++ 2008, others prefer to code in Emacs on GNU/Linux. We're wondering if it is possible for all of us to work more or less simultaneously out of both environments, from the same code repository. Ultimately we want the project to compile cleanly on both platforms from the start.

Any of our developers are happily willing to switch over to the other environment if this is not possible. We all use both Linux and Windows on a regular basis and enjoy both, so this isn't a question of trying to educate one set devs about the virtues of the other platform. This is about each of us being able to develop in the environment we enjoy most yet still collaborate on a fun project.

Any suggestions or experiences to share?

like image 630
Nack Avatar asked Aug 04 '09 19:08

Nack


People also ask

How is C cross-platform?

The language C itself is cross-platform, because you don't directly run C code on machines. The C source code is compiled to assembly, and assembly is the platform specific code. The only non cross-platform part are the compilers and the resulting assembly.

Is C supported by Linux?

Of course you can write C code on any OS, but there's a simplicity to FreeDOS that you might find refreshing. The sky's the limit, but even at ground level, you can do some amazingly fun things with C.

How do cross-platform libraries work?

Generally cross platform libraries are implemented in layers. There is the public interface, the common code, and a minimalized set of platform dependent code. The public interface usually uses #if defined(symbol) checks to determine which platform it is running on.

Are C++ libraries cross-platform?

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems. The POCO C++ Libraries are being used by C++ developers worldwide to build challenging and mission-critical applications.


2 Answers

Use CMake to manage your build files.

This will let you setup a single repository, with one set of text files in it. Each dev can then run the appropriate cmake scripts to build the correct build environment for their system (Visual Studio 2008/2005/GNU C++ build scripts/etc).

There are many advantages here:

  • Each dev can use their own build environment
  • Dependencies can be handled very cleanly, including platform specific deps.
  • Builds can be out of source, which helps prevent accidentally committing inappropriate files
  • Easy migration to new dev. environments (ie: when VS 2010 is released, some devs can migrate there just by rebuilding their build folder)
like image 138
Reed Copsey Avatar answered Oct 13 '22 14:10

Reed Copsey


I've done it and seen it done without too many problems.

You'll want to try an isolate the code that is different for the different platforms. Also, you'll want to think about your directory structure. Something like

  • project/src <- .cc and .h files
  • project/src/linux|win <- code that is specific to one platform or the other
  • project/linux <- make files and other project related stuff
  • project/win <- .sln and .csproj files

Basically you just want to be really clear what is specific to each system and what is common.

Also, unit tests are going to be really important since there may be minor difference and you want to make it easy for the windows guys to run some tests to make sure the linux code works as expected and the other way around.

like image 44
Alan Jackson Avatar answered Oct 13 '22 15:10

Alan Jackson