Boost logo

Boost :

From: Greg Chicares (chicares_at_[hidden])
Date: 2001-06-05 15:47:47


David Abrahams wrote:
>
> Is it acceptable for boost to build everything with -fPIC on platforms where
> it matters? (BTW, we are not supporting old broken compilers like egcs-1.1)

Suppose I write some application that uses some boost library a lot,
and -fPIC makes the application five percent slower. I wouldn't say
that's unacceptable, but I would be likely in that case to ignore the
boost build system (if it uses -fPIC) and write a makefile. But there
may be other issues...

> If the answer is YES, we can allow shared and static versions of any library
> to
> share object files. If the answer is NO, we must apply some target
> requirements based on target type. The question goes to the fundamental
> design of the build system, and whether shared and static libraries must be
> considered distinct top-level targets, or simply some kind of build variants
> of the same top-level target.
>
> Please think about this question in the context of your non-GCC compiler
> also. Analogous issues may exist.

Windows programmers often use a header like this:

#ifdef __WIN32__
# if defined(BOOST_BUILD_DLL)
# define BOOST_EXPIMP __declspec(dllexport)
# elif defined(BOOST_USE_DLL)
# define BOOST_EXPIMP __declspec(dllimport)
# else // neither build nor use dll
# define BOOST_EXPIMP
# endif // neither build nor use dll
#else // __WIN32__
# define BOOST_EXPIMP
#endif // __WIN32__

To build a DLL use -DBOOST_BUILD_DLL
To use a DLL use -DBOOST_USE_DLL
To build or use a static library use no special defines

The advantage of this approach is that the compiler and linker take care
of managing exports and imports. Alternatively, you can do that with a
so-called '.def' file--a plain text file that lists the symbols the DLL
makes available. If you want to be selective about which symbols are
'exported', then this can be a tedious manual task. Exporting by name
is relatively slow, so some programmers export by 'ordinal', which is
just an index number; that adds more chance for error, because the
ordinals can change when you change the code. There are tools that
create these .def files automatically, but again if you want to be
selective, it's probably easier to indicate which symbols to export
with __declspec attributes. Either you put them in the code, or you
have to do manual maintenance of the .def file. I think most people
use __declspec unless confronted with a DLL for which they don't
have the source.


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