Boost logo

Boost :

From: Schaible, Joerg (Joerg.Schaible_at_[hidden])
Date: 2000-10-20 02:04:43

Hi David,

> Sorry, I don't understand. Since all template member
> functions are inline in
> MSVC, how can they interact with anything at link time?

Just a little example hacked down here into the mail to illustrate the
problem for MSVC.

Code that will be provided in an DLL:

==== ExampleClass.hpp ======

#define EXAMPLE_EXPORT __declspec(dllexport)
#define EXAMPLE_EXPORT __declspec(dllimport)

#include <boost/smart_ptr.hpp>

class EXAMPLE_EXPORT InternalHelper

// Have to do export the instanciated template for MSVC to link the DLL
extern template class EXAMPLE_EXPORT boost::shared_ptr<InternalHelper>;

class EXPORT Example
boost::shared_ptr<InternalHelper> sptrHelper;
        template <class X> void print( const X& x ) { std::cout << x; }

======== EOF ====

I omit the .cpp. Now I show you the usage of this class from an application
using the DLL.

==== Application.cpp ======

#include <ExampleClass.hpp>

int main()
        Example e;
        return 0;

======== EOF ====

This will result in a linker error, if my code in the DLL never use this
instanciation of the member with an int. MSVC expects *every* instanciation
of the member template function coming out of that DLL and that is not


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