views:

103

answers:

3

Hi community,

I have recently started a new C++ project and I intend to make it cross-platform in time. I haven't had much experience with C++ projects before so the first thing that bothers me is that default Visual Studio file layout setup. I tried reading-up the Net on this subject but the info just seems rare and conflicting, so I started by doing something simple like this:

build
  vc2010  // Visual C++ solution/project files
lib 
  include // Header files for third-party libs
  // All library binaries here (like .lib, .dll or .so)
src
  // My own code (including headers)
temp
  // I use this as intermediate file output directory (for Visual C++)

Then Visual C++ project is configured to output final .exe in a root project directory (debug/release builds) so I can put there my own specific data as well (like data/ dir). Please note, I intend to manage my project under source version control repository (excluding some types like .exe) and I am not writing a library here. So my questions are:

Are there any de-facto standards for structuring your projects? Or are they platform and user specific?

How do you handle library dependencies? Do you just put pre-compiled binaries (like in my setup) or use full library source code and setup your project build process to include them in the process. Is it a good idea to put binary files under version control (like .lib/.dll in this case)?

+1  A: 

If you want to use Visual Studio (VC++ is usable without it), then there are some things you should be aware of. You can change where it gets its files from and where it puts them, so you aren't tied to its default structure. However, some of its subtools have loads of trouble with having different source files with the same name (in different directories, obviously), so that should be avoided.

Also, you have the standard Windows limitation that capitalization isn't significant in file names, so you have to stop your Unix folks from using that feature of their Unix filesystems.

T.E.D.
+1  A: 

Just keep in mind what happens when you switch to a different build system on another platform.

It won't know what to do with solution/project files, they're specific to Visual Studio. So it doesn't really matter how you structure that. You'll be re-doing it anyway.

Likewise with the temp directory, intermediate files are specific to the build system, they don't necessarily have to be off in their own tree. You'll probably want to stick with the default for each platform, whatever that is.

With third-party dependencies, you might find they're already installed (or can be installed) on the system you're porting to, in which case you might be happy to use the installed version, or you might depend on a very specific version. Either way, pre-compiled binaries are useless on another system.

So, if you want to take your third-party dependencies with you, and compile them wherever you go, then you need to treat them like your own sources, but in another root. Version-control the source but not the binaries. If you're going to use whatever's available pre-compiled for the target platform, you'll probably find you have to do things slightly differently on different platforms but that basically you'll either stick them somewhere, or find them somewhere already installed, and put that "somewhere" in your include path (for header files) and your linker path (for binaries).

You might want to version-control the binaries to be on the safe side, or you could just make a note what version you're using, and use backup rather than version control as your insurance against them being unavailable to download in future.

If you want to design for portability from the start, it might be a good idea to set things up for two different systems at the same time. You can do this without leaving Windows - for instance try installing Code::Blocks and build with MinGW as well as what you're already doing with Visual Studio.

Also beware that a lot of the libraries you'd naturally use on Windows, simply aren't available on other platforms. The build system will be the least of your worries if you've written a GUI app based on the Windows APIs, then you want to port it to OSX.

Steve Jessop
A: 

Just remember, no matter how hard you try to make it portable while developing in Visual Studio, it's going to break the first time you try to build / run it on any other platform.

If you want the project to be cross-platform, then I would recommend starting with at least two platforms from the beginning (e.g., Windows & Linux) and frequently make sure it builds / runs on both. I would also suggest starting with something other than Visual Studio...not because VS is bad...it's just not ideal for setting up a cross-platform project. I like CMake and out-of-source builds.

If the app will have a GUI, use a portable GUI library like wxWidgets, QT, etc.

Stick with stuff that's known to be portable...boost, libxml2, ODBC, etc.

dgnorton