Boost logo

Boost :

From: Ehsan Akhgari (ehsan_at_[hidden])
Date: 2003-09-13 04:26:45


> This seems most convenient, for example requiring just:
>
> #pragma comment( lib, "unit_test_library.lib" )

Users won't need to specify this. You can put the above #pragma inside
the header file unit_test.hpp. And if the header is included in
multiple translation units, there will be no "duplicate symbol" errors
or such.

> and
>
> #include <boost/test/unit_test.hpp> // for unit_test framework
>
> in the test file,

The *only* requirement would be the above #include. See above and
below.

> and setting the 'global' library directory using
>
> Tools, Options, Projects, VC++ Directories, drop-down
> selecting library instead of executables, and adding a new item
>
> J:\Cpp\Unit_test_library\Debug
>
> or
>
> J:\Cpp\Unit_test_library\Release

Actually this can also be avoided by copying the lib files in the VC++'s
lib directory (for example: C:\Program Files\Microsoft Visual Studio
.NET 2003\Vc7\lib for VC++ 7.1). This can be done using a makefile for
the build. See the Regex++ vc7 makefile
(BOOST_ROOT\libs\regex\build\vc7.mak) for an example. It would be
something like:

install : all
        copy vc7\boost_regex_vc7_sss.lib "$(MSVCDIR)\lib"

I don't know if this can be done using bjam or not - perhaps someone
else with more experience of bjam would guide us.

> However perhaps you can advise how to make this work to
> select the right library for release and debug modes.
>
> J:\Cpp\Unit_test_library\$(ConfigurationName) doesn't appear
> to work in this context in release mode. (Lots of duplicate
> libc. ... at link stage).

I usually do something like this for my own libraries:

#ifdef _DEBUG
#ifdef _UNICODE
#pragma comment(lib, "ModuleManagerud.lib")
#pragma message("Automatically linking with ModuleManagerud.lib ...")
#else
#pragma comment(lib, "ModuleManagerd.lib")
#pragma message("Automatically linking with ModuleManagerd.lib ...")
#endif
#else
#ifdef _UNICODE
#pragma comment(lib, "ModuleManageru.lib")
#pragma message("Automatically linking with ModuleManageru.lib ...")
#else
#pragma comment(lib, "ModuleManager.lib")
#pragma message("Automatically linking with ModuleManager.lib ...")
#endif
#endif

In the above example, I select the correct library with regard to build
config (debug vs. release) and character code (unicode vs. non-unicode.)
You can switch on the runtime library selected as well: (multithreaded
vs. single-threaded; using the _MT preprocessor symbol) and (static vs.
dynamic linking: using the _DLL preprocessor symbol.) You just need to
pick a naming convention, like I have in the above example:

 ModuleManager: base lib name
 u: Unicode build (absence of u: non-Unicode build)
 d: Debug build (absence of d: release build)
 // and so on...

So, for the user, it will be as simple as building using the shipped
makefile (or JamFile) and #including the appropriate header. Couldn't
be any easier, could it?

-------------
Ehsan Akhgari

List Owner: MSVC_at_[hidden]

[ Email: ehsan_at_[hidden] ]
[ WWW: http://www.beginthread.com/Ehsan ]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk