views:

619

answers:

2

Hello all,

I'm curious about everyones practices when it comes to using or distributing libraries for an application that you write.

First of all, when developing your application do you link the debug or release version of the libraries? (For when you run your application in debug mode)

Then when you run your app in release mode just before deploying, which build of the libraries do you use?

How do you perform the switch between your debug and release version of the libraries? Do you do it manually, do you use macros, or whatever else is it that you do?

+2  A: 

I would first determine what requirements are needed from the library:

  1. Debug/Release
  2. Unicode support
  3. And so on..

With that determined you can then create configurations for each combination required by yourself or other library users.

When compiling and linking it is very important that you keep that libraries and executable consistent with respect to configurations used i.e. don't mix release & debug when linking. I know on the Windows/VS platform this can cause subtle memory issues if debug & release libs are mixed within an executable.

As Brian has mentioned to Visual Studio it's best to use the Configuration Manager to setup how you want each configuration you require to be built.

For example our projects require the following configurations to be available depending on the executable being built.

  1. Debug+Unicode
  2. Debug+ASCII
  3. Release+Unicode
  4. Release+ASCII

The users of this particular project use the Configuration Manager to match their executable requirements with the project's available configurations.

Regarding the use of macros, they are used extensively in implementing compile time decisions for requirements like if the debug or release version of a function is to be linked. If you're using VS you can view the pre-processor definitions attribute to see how the various macros are defined e.g. _DEBUG _RELEASE, this is how the configuration controls whats compiled.

What platform are you using to compile/link your projects?

EDIT: Expanding on your updated comment..

If the Configuration Manager option is not available to you then I recommend using the following properties from the project:

  • Linker->Additional Library Directories or Linker->Input

Use the macro $(ConfigurationName) to link with the appropriate library configuration e.g. Debug/Release.

$(ProjectDir)\..\third-party-prj\$(ConfigurationName)\third-party.lib
  • Build Events or Custom Build Step configuration property

Execute a copy of the required library file(s) from the dependent project prior (or after) to the build occurring.

xcopy $(ProjectDir)\..\third-party-prj\$(ConfigurationName)\third-party.dll $(IntDir)

The macro $(ProjectDir) will be substituted for the current project's location and causes the operation to occur relative to the current project. The macro $(ConfigurationName) will be substituted for the currently selected configuration (default is Debug or Release) which allows the correct items to be copied depending on what configuration is being built currently.

If you use a regular naming convention for your project configurations it will help, as you can use the $(ConfigurationName) macro, otherwise you can simply use a fixed string.

Henk
A: 

I use VS. The way that I do it is that the libraries I need through the references of the project. Which basically just says in what folder to look for a specific library at project load time. I develop my libraries to be as project independent or reusable as possible. Therefore they are all projects of their own. So of the libraries that I need for a specific project, I create a "3rdParty" or "libs" folder at the same level as my "src" folder in my svn folder tree. I tend to only use released libraries, but when I get some unknown issues and want to switch to debug, I manually copy a debug version of the files in the "lib" folder and reload the project.

I am unsure wether I should be keeping both debug and released versions in my svn tree. Although since they are projects of their own, keeping them in the svn tree of another project doesn't right. They can be built again without an hitch at any moment.

And then I wanted to find a way of making the switch more...hmmm...well basically automatic if you while, but that's not what I really mean. It just feels that switching the files manually between released and debug isn't right. Maybe I haven't found it yet, but what I would like is an option that would do like: For library "stack.dll" look in "......\3rdParty\" for release and "......\3rdPartyD\" for debug.

Anything that those something like I don't know. What do you suggest? Remember libraries are external projects. There the built files are totally elsewhere. In fact think of it as you have to check out another project, build it, and copy the built library if you want another copy. How would you set that up?

Dewm Solo