473,802 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[!! 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 1598
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(dlle xport)
#else
#define CCONV __declspec(dlli mport)
#endif

class CCONV MyClass {
public :
MyClass():m_nam e("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 doThisToMyNestE gg( void ) { m_nuts.doThis() ; }
inline void doThatToMyNestE gg( 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<MyCla ss> { ...}

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<typena me 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(dlle xport)
#else
#define CCONV __declspec(dlli mport)
#endif

class CCONV MyClass {
public :
MyClass():m_nam e("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 doThisToMyNestE gg( void ) { m_nuts.doThis() ; }
inline void doThatToMyNestE gg( 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<MyCla ss> { ...}

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.as ianetindia.com> wrote in message
news:uV******** ******@TK2MSFTN GP10.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<typena me 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(dlle xport)
#else
#define CCONV __declspec(dlli mport)
#endif

class CCONV MyClass {
public :
MyClass():m_nam e("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 doThisToMyNestE gg( void ) { m_nuts.doThis() ; }
inline void doThatToMyNestE gg( 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<MyCla ss> { ...}

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********@hot mail.com> wrote in message
news:eP******** ******@TK2MSFTN GP14.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
4861
by: Nahappan SM | last post by:
I have a struct : #include <string> struct __declspec (dllexport) FILEPROPERTIES { std::wstring FileName; std::wstring Type; };
11
2138
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 transcript of a historical legal document with signatures on the right and witnesses on the left). The 'document' ends with no additional inline text. The background of the entire document should be brown inside a white body, (in this test the body...
5
6447
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, the following condition exists: class A {} ; // Instantiated in the static library and specified // in a header included by all clients. // // This is the class using A that is exported by a DLL.
2
31665
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 'MyClass' D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\af xcoll.h(367) : see declaration of 'CPtrArray' How can I get rid of the warnings.
0
863
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 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'ClassA' with
6
2389
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 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'ClassA' with
2
11683
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 best IE6 hack that IE7 will ignore? Should I load different style sheets based up the browser (like this) <!--> <link rel="stylesheet" href="IE6-style.css" type="text/css" /> <!-->
13
2285
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 virtual functions, and functions you can call to instantiate and delete objects of the type. You can then just call virtual functions on the type."
6
4598
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 have access via a protected "print"-method. I need the different dlls as the sub classes implement the base class's pure virtual methods using different technologies. To use the native classes from outside their dlls I use the...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.