Tamas Demjen wrote :
> This is one of those very few cases where you can't get rid of the
> warnings without the #pragma. There are some macros on this site:
> http://www.unknownroad.com/rtfm/Visu...ningC4251.html
>
> But first, they don't work with any modern VC++ (7.1, 8.0). So I tried
> to create my own version that worked (http://tweakbits.com/DllExport.h),
I also use this trick in _DEBUG only, because in release I don't use
dlls. I also recommend not to export STL classes, e.g. not to use STL
types in dll interfaces.
> #define EXPORT_STL_VECTOR(declspec_, T_) \
> template class declspec_ std::allocator<T_ >; \
> template class declspec_ std::vector<T_ >;
I recently modified this macros not to explicitly instanciate the vector
if the declspec_ is not defined to __declspec( something ) because I ran
into troubles in some very special circumstances.
Since in my case I export the vector in _DEBUG only, it looks like:
#ifdef _DEBUG
#define EXPORT_STL_VECTOR(declspec_, T_) \
template class declspec_ std::allocator<T_ >; \
template class declspec_ std::vector<T_ >;
#else
#define EXPORT_STL_VECTOR(declspec_, T_)
#endif
Otherwise, with such a define:
#ifdef _DEBUG
....
#else
#define MYEXPORT /*empty*/
#endif
The EXPORT_STL_VECTOR( MYEXPORT, int ) would expand in Release in an
explicit specialisation:
template class std::allocator<int>;
template class std::vector<int>;
which is at least not very useful.
>> 3). Is this fixed in VC8 (2005)?
>
>
> No, the warning is still there. The compiler doesn't know that it's
> compiling STL, and if it was not STL, the warning would (could) be valid.
I don't know how they can fix it. If you compile a dll which asks for a
std::string with VC++ 6 and use this same dll from your VC++ 8 app, you
will get a problem because each compiler uses its own std::string, and
VC++ 8 will call std::string::c_str() of its STL on a VC++ 6 std::string
instance...
Even with the same compiler it is a problem, because the dll and the exe
both use their own std::string specialisation. If they are compiled with
the same compiler, they use the same code, but this code is still
duplicated. In fact, you have 2 same std::string types in you process :
the dll one and the exe one. They can be the same, but they can also be
different. For example, if your dll compiles std::vector with
_SECURE_SCL defined, and your exe doesn't, your app may crash.
--
Aurélien Regat-Barrel