Solved

Getting rid of dllimport warning messages for template classes

Posted on 2004-08-20
3
314 Views
Last Modified: 2010-04-01
Hi,

I'm tired of stuff like this:

// File: foo.h

class __declspec(dllimport) foo
{
  int x;
  vector<int> xs;
};

When including foo.h you will get a bunch of warnings about vector<> (or it's allocator) not being dllexported:

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(35) : warning C4251: 'std::_Vector_val<_Ty,_Alloc>::_Alval' : class 'std::allocator<_Ty>' needs to have dll-interface to be used by clients of class 'std::_Vector_val<_Ty,_Alloc>'

Of course, vector isn't dllexported because it is a template class, and its implementation is entirely contained within the relevant header files.  Is there some way to avoid these warning?

Unacceptable solutions are:

(1) using #pragma warning(disable: xxxx) or similar to simply surpress the errors
(2) changing any of the standard header files
(3) Changing the dllexport nature of the client class (foo), for example by only exporting specific functions



0
Comment
Question by:travd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 11857349
As I just posted the same in another Q: Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;168958 ("How To Exporting STL Components Inside & Outside of a Class") and http://support.microsoft.com/default.aspx?scid=kb;en-us;172396 ("PRB: Access Violation When Accessing STL Object in DLL")

Templates and DLLs can cause problems if you do not offer proper access (via e.g interfaces) to these objects, which better only "live" inside the modukes they're created in.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why isn't object file created? 6 108
Where are the c++ header files to use in Eclipse? 4 77
print bytes of an integer 6 48
keep track of class structure 1 55
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question