views:

83

answers:

4

I come from a Java background, and the shop where I currently work refuses to use anything other than MS VC++ to build their legacy project. They don't appear to use any standards for setting up their build environment other than just building it using VS2005 and clicking the compile button.

I was wondering if there was anything closer to what Java had for instance:

  • A build tool like ANT or Maven
  • A directory structure that makes sense containing
    • src - Place for all my source files .c/.cpp/.h
    • lib - A place for any libraries that might be used in the project (.dll, .lib)
    • dist - A place for the output executable/distribution of the project
    • resources - A place for any images/sounds/text files that might be included in the project.
    • build.xml - Some sort of a build file (my guess would be something like ./configure or MAKEFILE)

Or am I asking too much from a C++ build environment? Is it just always as chaotic as the people in my shop make it out to be? I really have a hard time believing that considering the success of so many C++ projects on the internet.

A: 

The standardized stuff:

  • The build tool: Visual Studio (doesn't need an extra product)
  • Build file: *.sln / *.vcproj (*.vbproj for Visual Basic, etc)
  • Directory structure: "Debug" and "Release" directories for the output binaries.

The rest isn't so much "chaotic" as "doesn't really matter". "Chaotic" suggests that it changes all the time, but in reality you just pick one for a project and stick with it. Companies may have internal standards across projects. It just doesn't matter enough to bother standardizing across companies. C++ is a complex language anyway; anyone with sufficient IQ to read C++ can deal with reasonable variation. The difference between \lib\ and \Library\ won't stop them.

MSalters
Aren't Linux C++ directory structures a tad more organized than this?
leeand00
Also, how do you know what order the projects are compiled in?
leeand00
It is only convention that makes any structure appear organized or not. Under g++, you can put things anywhere you want, if you make the effort. Same with Visual Studio.If you're asking what the order of compilation is in Visual Studio, why does it make any difference? At any rate, you can specify the structure. Read the documentation.
jfawcett
@leeand00 The order of compilation of projects in a solution is determined by inter-project dependency data stored in the *.sln file.
Nick Meyer
... if you right-click on a project in the Solution Explorer, you can click "Project Dependencies" to edit these dependencies and "Project Build Order" to see the build order VS calculated based on the dependencies you specified.
Nick Meyer
+1  A: 

MSVC does not impose any directory structure on you. There are some defaults, as mentioned above for the Debug and Release directories, for example, but even these can be overridden on a per-project basis. Use whatever directory structure makes sense to you.

Visual Studio does provide command line support if you don't want to use the IDE. See This MSDN Article for more information.

jfawcett
+1  A: 

You can setup a proper build environment using Visual Studio (and for solutions with more than one project, you should), and there are a number of environment variables to use in the project configuration to set so that output files and intermediate files go to different folders than those defined by default.

In our large VS solution, we use e.g. obj/$(ProjectName)/$(ConfigurationName) as intermediate directory and bin/$(ConfigurationName) as output directory in all sub-projects.

All these things must be enforced by the user, and it seems that no single recommendation/best practice has evolved.

MP24
+1  A: 

It sounds like you have good intentions - coming form a non MSVC world I can see your points.

If I were in y our shoes I would definitely make a command line/automated build/build server.

You can use MSBuild for this - and hudson has a plugin for this. I usually have a "Build" directory near the root of the projects that contains scripts/etc that will call the appropriate MSBuild/.sln files.

The "makefiles" for Visual Studio are .sln and .vcproj files. You can call those with msbuild from the command line. You can also export a makefile (I think that is still an option) from within the IDE that you can run. I don;t recommend going that route though other than trying it out and seeing what is output - since that is what you are familiar with.

Both the vcproj and sln files are human readable - go through them - it will give you some useful information.

I would also agree that having a distributon directory is good - for building an installer/etc after the build. Copy all the needed binaries there - either in postbuild steps or in another script/etc.

Let us know what you end up doing.

I have one other piece of advice: UPGRADE to VC/Dev studio 2008 or 2010. ASAP

Tim
@tim Cool I didn't know those .vcproj and .sln files were human readable! :) I probably have some old (perhaps unfounded) biases against MS. I know that they've taken steps to get better in recent years.
leeand00