473,382 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

[!! RANT !!] This is a hack at best (C4251)

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 !

Nov 17 '05 #1
7 1575
firstly, the latest microsoft compiler is more standards compliant than gcc,
or most other compilers. gcc is about the worst when ot comes to standards
compliance.

secondly, AFAIK, template code is handled by the preprocessor in some sort
of copy and paste action to generate the correct code. it only makes sense
that you cannot export raw templates from binary code. gcc does not allow
you to do this.

third: things like Micro$oft and Windoze do not make you funny. I do not
talk about LinSucks either, and btw, do you think that IBM is on the linux
train because they are huggy feeling types?


"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 !

Nov 17 '05 #2

"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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #3


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

Nov 17 '05 #4
The template function won't be generated until it's instantiated. So, you
really cannot export template functions from a DLL. The right way to use
templates is via a header file.

Or you could use the below technique (quite ugly I might add) :-

e.g. :-

template<typename T> void foo(T t) {...}
//export the below functions

void fooint(int t)
{
foo<int>(t);
}

void foochar(char t)
{
foo<char>(t);
}

void fooCWnd(CWnd t)
{
foo<CWnd>(t);
}

etc . . .

Export functions for every possible template specialization that the calling
code might need.

But again, the right way to do this is to include the header file defining
the template function in your calling project.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...


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

Nov 17 '05 #5
Also see http://support.microsoft.com/default...b;EN-US;168958

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Nishant Sivakumar" <ni**@nospam.asianetindia.com> wrote in message
news:uV**************@TK2MSFTNGP10.phx.gbl...
The template function won't be generated until it's instantiated. So, you
really cannot export template functions from a DLL. The right way to use
templates is via a header file.

Or you could use the below technique (quite ugly I might add) :-

e.g. :-

template<typename T> void foo(T t) {...}
//export the below functions

void fooint(int t)
{
foo<int>(t);
}

void foochar(char t)
{
foo<char>(t);
}

void fooCWnd(CWnd t)
{
foo<CWnd>(t);
}

etc . . .

Export functions for every possible template specialization that the
calling code might need.

But again, the right way to do this is to include the header file defining
the template function in your calling project.

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Alfonso Morra" <sw***********@the-ring.com> wrote in message
news:dc**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...


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


Nov 17 '05 #6
Bruno van Dooren wrote:
firstly, the latest microsoft compiler is more standards compliant than gcc,
or most other compilers. gcc is about the worst when ot comes to standards
compliance.
GCC 4.0 is more compilant than VC8 as far as I know (it has two phase
name lookup for a start). GCC implements everything except export,
whereas VC implements everything except export, two phase name lookup,
and a few other features. See
http://msdn2.microsoft.com/library/x...us,vs.80).aspx for VC
problems and this much shorter list or compliance issues for GCC:
http://gcc.gnu.org/bugs.html#known
secondly, AFAIK, template code is handled by the preprocessor in some sort
of copy and paste action to generate the correct code.


Templates are handled by the compiler, not the preprocessor, but they
can't be fully compiled until instantiation time.

Tom
Nov 17 '05 #7

"Tom Widmer [VC++ MVP]" <to********@hotmail.com> wrote in message
news:eP**************@TK2MSFTNGP14.phx.gbl...
Bruno van Dooren wrote:
firstly, the latest microsoft compiler is more standards compliant than
gcc, or most other compilers. gcc is about the worst when ot comes to
standards compliance.
GCC 4.0 is more compilant than VC8 as far as I know (it has two phase name
lookup for a start). GCC implements everything except export, whereas VC
implements everything except export, two phase name lookup, and a few
other features. See
http://msdn2.microsoft.com/library/x...us,vs.80).aspx for VC
problems and this much shorter list or compliance issues for GCC:
http://gcc.gnu.org/bugs.html#known

i have not yet looked at gcc 4.0, but i knew my statements to be true for
gcc 3.0
secondly, AFAIK, template code is handled by the preprocessor in some
sort of copy and paste action to generate the correct code.
Templates are handled by the compiler, not the preprocessor, but they
can't be fully compiled until instantiation time.

didn't know that. thanks.

Tom

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nahappan SM | last post by:
I have a struct : #include <string> struct __declspec (dllexport) FILEPROPERTIES { std::wstring FileName; std::wstring Type; };
11
by: Chris Beall | last post by:
Here's the problem: http://pages.prodigy.net/chris_beall/Demo/theproblem.html The page contains inline text, then some additional pairs of text which are floated right and left. (This is a...
5
by: Robert A Riedel | last post by:
I have a class that is intended to be exported in a DLL that uses another class that is in a static library. All clients that use the DLL will also link with the same static library. In summary,...
2
by: Siemel Naran | last post by:
I keep getting warning messages like these: ....\include\myfile.h(451) : warning C4251: 'MyClass::m_myvariable' : class 'CPtrArray' needs to have dll-interface to be used by clients of class...
0
by: Bart Simpson | last post by:
I am writing a shared object (Dll in Windows) and I am making extensive use of the STL. I am getting lots of warnings like this: ClassA.h(139): warning C4251: 'ClassA::indexarray' : class...
6
by: Bart Simpson | last post by:
I am writing a shared object (Dll in Windows) and I am making extensive use of the STL. I am getting lots of warnings like this: ClassA.h(139): warning C4251: 'ClassA::indexarray' : class...
2
by: mark4asp | last post by:
What is the best way to write a page that uses min-width and max-width and will work IE6, IE7 and other modern browsers? I realise that I need a hack for IE6 but not for IE7 so what is the...
13
by: Anonymous | last post by:
On MS site: http://msdn2.microsoft.com/en-us/library/esew7y1w(VS.80).aspx is the following garbled rambling: "You can avoid exporting classes by defining a DLL that defines a class with...
6
by: =?Utf-8?B?RmFiaWFu?= | last post by:
Hello, I have a class hierarchy distributed over 3 native C++ dlls. The base class has a .NET Windows.Form for status output via a gcroot<>. The gcroot is declared private - the sub classes only...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.