You are not logged in.

1

Tuesday, August 9th 2011, 9:29am

Warning: C4251

Hello forum,

I have a special problem with my solution, which consists of several projects, each compiled as an *.dll, except one of those, which is the executable *.exe. I develop that in Visual Studio 2008 under Xp Pro.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1>c:\qt\qt-win-opensource-src-4.5.0\include\qtcore\../../src/corelib/codecs/qtextcodec.h(106) : warning C4251: 'QTextCodec::ConverterState::flags' : class 'QFlags<Enum>' needs to have dll-interface to be used by clients of struct 'QTextCodec::ConverterState' 

1> with 
1> [ 
1> Enum=QTextCodec::ConversionFlag 
1> ] 
1>c:\qt\qt-win-opensource-src-4.5.0\include\qtcore\../../src/corelib/concurrent/qtconcurrentexception.h(101) : warning C4251: 'QtConcurrent::internal::ExceptionStore::exceptionHolder' : class 'QtConcurrent::internal::ExceptionHolder' needs to have dll-interface to be used by clients of class 'QtConcurrent::internal::ExceptionStore' 
1> c:\qt\qt-win-opensource-src-4.5.0\include\qtcore\../../src/corelib/concurrent/qtconcurrentexception.h(83) : see declaration of 'QtConcurrent::internal::ExceptionHolder' 
1>c:\qt\qt-win-opensource-src-4.5.0\include\qtcore\../../src/corelib/concurrent/qtconcurrentresultstore.h(98) : warning C4251: 'QtConcurrent::ResultIteratorBase::mapIterator' : class 'QMap<Key,T>::const_iterator' needs to have dll-interface to be used by clients of class 'QtConcurrent::ResultIteratorBase' 
1> with 
1> [ 
1> Key=int, 
1> T=QtConcurrent::ResultItem 
1> ] 
1> c:\qt\qt-win-opensource-src-4.5.0\include\qtcore\../../src/corelib/tools/qmap.h(268) : see declaration of 'QMap<Key,T>::const_iterator' 
1> with 
1> [ 
1> Key=int, 
1> T=QtConcurrent::ResultItem 
1> ] 
1>c:\qt\qt-win-opensource-src-4.5.0\include\qtcore\../../src/corelib/concurrent/qtconcurrentresultstore.h(146) : warning C4251: 'QtConcurrent::ResultStoreBase::m_results' : class 'QMap<Key,T>' needs to have dll-interface to be used by clients of class 'QtConcurrent::ResultStoreBase' 
1> with 
1> [ 
1> Key=int, 
1> T=QtConcurrent::ResultItem 
1> ] 
1> // .... and so on


In one of my projects I have a kind of a major class, this has no Q_OBJECT macro. In this project I added another class (nothing special just a few attributes and their getters). And since I included this new class in my first mentioned major class, I got these warnings.

I had this warning before with classes where Q_OBJECT was set; therefore I just added for each header file:

Source code

1
2
3
4
5
6
7
#ifdef CURRENTLY_COMPILING_LIBRARY 
#define IMPORT_OR_EXPORT_SYMBOL Q_DECL_EXPORT 
#else 
#define IMPORT_OR_EXPORT_SYMBOL Q_DECL_IMPORT 
#endif 
///... 
class IMPORT_OR_EXPORT_SYMBOL LibraryClass { ... }
and those warnings were gone (work only for Q_OBJECT?).

Anybody of you have any hints for me?

Thanks in advise. Cheers
Huck

Junior

Professional

  • "Junior" is male

Posts: 1,623

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

2

Wednesday, August 10th 2011, 7:09pm

Found this on a blog and thought it might be helpful.

Quoted

It's nothing #pragma warning(disable) can't cure. :)


It merely hides it. Think about the motivation for this warning. It's
emitted when you use a non-dllexported class X in a dllexported class Y.
What's so bad about that? Well, suppose Y has an inline function y_f that
calls a function x_f belonging to X that is not also inline. If y_f is
inlined inside some client that doesn't statically link X, the link will
fail, because x_f won't be found. Concerning your code, ThirdPartyTemplate
is a class template, and template code is generated wherever it's needed,
so this is not an issue. You may end up with some code bloat due to
duplicated template instantiations, but you can usually ignore this. There
are two workarounds (and I use that term lightly):

1. You can explicitly instantiate and dllexport the specializations you use
from some DLL, or more generally,

2. You can define a wrapper class that has no inline functions and defines
all the potentially compiler-generated functions (default ctor, copy ctor,
dtor, and assignment operator) and dllexport that.

It looks like you're sort of on your way to (2) with MyClass.

--
Doug Harrison
Visual C++ MVP

Similar threads

Used tags

c4251, export, msvc, Q_OBJECT, warning