Boost logo

Boost :

From: Greg Clayton (Greg.Clayton_at_[hidden])
Date: 2004-03-10 13:37:07

I am trying to do explicitly instantiate specific shared_ptr class for export from a Win32 DLL (currently with MSVC6, and eventually in VS2003). I have followed the Win32 rules found at:

and have something like:

// Provide the storage class specifier (extern for an .exe file, null
// for DLL) and the __declspec specifier (dllimport for .an .exe file,
// dllexport for DLL).
// You must define EXP_STL when compiling the DLL.
// You can now use this header file in both the .exe file and DLL - a
// much safer means of using common declarations than two different
// header files.
#ifdef EXP_STL
# define DECLSPECIFIER __declspec(dllexport)
# define DECLSPECIFIER __declspec(dllimport)
# define EXPIMP_TEMPLATE extern

EXPIMP_TEMPLATE template class DECLSPECIFIER boost::shared_ptr<SomeClass>;

When I look through the exports, some needed class functions seem to be missing from the DLL, and linking fails. Most notable are:

void boost::shared_ptr<SomeClass>::reset(SomeClass*)

This function is declared in the shared_ptr header file as:
        template<class Y> void reset(Y * p);

The reset function which does not take an argument is in the export list which is defined as:
      void reset(); // never throws

And if I have a forward declaration of class followed by explicit instantiation, such as found below:

class SomeClass;
EXPIMP_TEMPLATE template class DECLSPECIFIER boost::shared_ptr<SomeClass>;

The constructor that takes a class pointer is not generated:

public: __thiscall boost::shared_ptr<class SomeClass>::shared_ptr<class SomeClass>(class SomeClass *)

which is declared as:
        template<class Y> explicit shared_ptr(Y * p);

Do I need to do extra explicit instantiations for the class members whose declarations start with "template<class Y>"? If so how does this syntax work?

Any help or tips would be most appreciated.

Greg Clayton

Boost list run by bdawes at, gregod at, cpdaniel at, john at