B
Bob Altman
Hi all,
I have a class that is exported from a DLL. This class includes a private
std::vector<int>. I followed the instructions in this KB article
<http://support.microsoft.com/kb/q168958/> to create a sample app. When I
compile the sample app I get a C4251 warning
('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>') in the STL "vector" header.
What magic incantation do I need to perform to get this to compile
correctly?
To repro this problem:
1. Create a new Win32 Console App project named DLLTest. I'm using VS 2005
SP1, but I imagine you'll get the same behavior in VS 2008.
2. Click on Application Settings, select DLL and Export Symbols, and click
on Finish.
3. Replace DLLTest.h with this code:
// --- DLLTest.h---
#ifdef DLLTEST_EXPORTS
#define DLLTEST_API __declspec(dllexport)
#define DLLTEST_EXTERN
#else
#define DLLTEST_API __declspec(dllimport)
#define DLLTEST_EXTERN extern
#endif
#include <vector>
// Instantiate vector<int>
DLLTEST_EXTERN template class DLLTEST_API std::vector<int>;
// This class is exported from the DLLTest.dll
class DLLTEST_API CDLLTest {
private:
std::vector<int> m_test;
};
// --- End of code ---
TIA - Bob
I have a class that is exported from a DLL. This class includes a private
std::vector<int>. I followed the instructions in this KB article
<http://support.microsoft.com/kb/q168958/> to create a sample app. When I
compile the sample app I get a C4251 warning
('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>') in the STL "vector" header.
What magic incantation do I need to perform to get this to compile
correctly?
To repro this problem:
1. Create a new Win32 Console App project named DLLTest. I'm using VS 2005
SP1, but I imagine you'll get the same behavior in VS 2008.
2. Click on Application Settings, select DLL and Export Symbols, and click
on Finish.
3. Replace DLLTest.h with this code:
// --- DLLTest.h---
#ifdef DLLTEST_EXPORTS
#define DLLTEST_API __declspec(dllexport)
#define DLLTEST_EXTERN
#else
#define DLLTEST_API __declspec(dllimport)
#define DLLTEST_EXTERN extern
#endif
#include <vector>
// Instantiate vector<int>
DLLTEST_EXTERN template class DLLTEST_API std::vector<int>;
// This class is exported from the DLLTest.dll
class DLLTEST_API CDLLTest {
private:
std::vector<int> m_test;
};
// --- End of code ---
TIA - Bob