Peter van der Goes wrote:
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:db**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I cannot believe how convoluted it is to export function templates and
class templates from a shared library (or DLL as it is called in the
Windoze world).
Micro$oft support for STL and standards in general is absolutely appaling.
This is absolutely ridiculous. I have obtaind links from people who tried
to help me solve this problem, several days ago, to no avail. Even the
sample code at http://support.microsoft.com/kb/q168958/ when adapted to my
code (i.e. #defines specified etc), still generates compiler errors like:
error C2757: 'std' : a symbol with this name already exists and therefore
this name cannot be used as a namespace name
This is from code provided by Microsoft. I TRULY HATE Microsoft (there I
said it), and their non-standard, proprietary way of doing everything. I
would not touch their flaky compilers if I did not have to work with them
...Arghhhh, I'm going out for a cofee break !
Perhaps when you return from your break, you'll provide some amplifying
information about the problem you are having? That might make it possible
for someone here to help you.
Hi peter,
Thanks for offering to help. This is really driving me round the bend. I
have a little sample code below, which compiles and builds (with
warnings). The built DLL exports the symbols, so I am not sure why the
compiler issues the warnings (however, I have not tried to use the built
DLL).
Here is the code:
using std::string ;
using std::vector ;
#ifdef TESTDLL_EXPORTS
#define CCONV __declspec(dllexport)
#else
#define CCONV __declspec(dllimport)
#endif
class CCONV MyClass {
public :
MyClass():m_name("test"),val(0){} ;
~MyClass(){} ;
inline string getName( void ){ return m_name ; }
inline void setName( string new_name ) { this->m_name = new_name ; }
template <class T1, class T2>
void foo( T1 arg1, T2 arg2 ) {
;//dummy
};
inline vector<int> getDates( void ){ return dates ; }
private:
//prevent copy and assignment
MyClass( const MyClass& ) ;
MyClass& operator=(const MyClass&) ;
/* Nested class */
class MyNestEgg {
friend class MyClass ;
void doThis(void){;}
void doThat(void){;}
};
string m_name ;
int val ;
MyNestEgg m_nuts ;
vector<int> dates ;
public:
inline void doThisToMyNestEgg( void ) { m_nuts.doThis() ; }
inline void doThatToMyNestEgg( void ) { m_nuts.doThis() ; }
};
Two thing I must mentioned however, are:
1). I notice that the compiler does not complain about the myNestEgg
variable. In my actual code, the compile complains as ff:
"warning C4251: 'A::m_props' : class 'A::Properties' needs to have
dll-interface to be used by clients of class 'A'
2). The function template is completely ignored and not even exported.
This is not too suprising since it may require template specialiazation
- but this is only a guess, siince I cannot find anything useful on
Microsoft's site - and the code given there to allow exporting STL
objects from a shlib does not work.
I hope you can provide a fix as to how to get this to work (i.e. compile
without warnings and to export STL classes). The actual code I have
inherits from a template class like this:
MyClass: public Singleton<MyClass> { ...}
For now, i want to keep things simple, and I will discuss that once I
have managed to get the simple class (i.e. with no inheritance
extensions) to compile and export symbols correctly.
MTIA