473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to get rid off -- warning C4251: needs to have dll-interface

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.

I put the following

#pragma warning(disable: 4251)

at the top of the cpp file I am compiling, as well as the top of stdafx.h,
but it does not work.

Thanks.
Jan 17 '06 #1
2 31558
did you recompile StdAfx.h when you added #pragma warning(disable: 4251) ?
the precompiled header will not be recreated automatically.

also, why don't you use __declspec(dllexport) to get rid of the warning?

another approach would be to do something like this in your header file:

#pragma warning(push)
#pragma warning(disable:4251)
//your declarations that cause 4251
#pragma warning(pop)

kind regards,
Bruno.

"Siemel Naran" schreef:
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.

I put the following

#pragma warning(disable: 4251)

at the top of the cpp file I am compiling, as well as the top of stdafx.h,
but it does not work.

Thanks.

Jan 18 '06 #2
Localizing the pragma to the header file causing it is preferred and is what
we do. Also, because we build on multiple compilers and platforms,

#if defined (_MSC_VER)
# pragma nonesense
#endif

The push and pop are very good tips because it contains the explosion only
to the code affected regardless of who uses it.

It's a very annoying warning to have on by default because it assumes
anything the exported class will use is also exported. If your class
restricts access to these members being warned about internally, there's no
problem.

The suggestion of __declspec(dllexport)'ing the affected member of the
exported class isn't always viable or necessary. For example, I routinely
export classes in dll's using stl containers which makes it impossible to
supress the warning without a #pragma or command line switch. I don't expect
or allow the client to directly twink the member variable or any references
to it so there's no problem.

For the warning to make more sense, it should be smart about only activating
in unsafe cases, like:

exported class is inherited from non-exported class
public member variable
public function returning or taking non-exported class type
public function using throw () decl with non-exported class type
...etc

Or even better moving the warning to the linker where it can determine with
certainty if there really is a problem.

While we're having all this __declspec() crap thrown upon us, why not add
another one which explicity marks the symbol "not-for-export"?
"Bruno van Dooren" wrote:
did you recompile StdAfx.h when you added #pragma warning(disable: 4251) ?
the precompiled header will not be recreated automatically.

also, why don't you use __declspec(dllexport) to get rid of the warning?

another approach would be to do something like this in your header file:

#pragma warning(push)
#pragma warning(disable:4251)
//your declarations that cause 4251
#pragma warning(pop)

kind regards,
Bruno.


Jan 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bolin | last post by:
I was wondering how to properly export template classes that are defined in a library. The problem is that this library defines a template class: template <typename T> class A {...}; and...
1
by: Peter Steele | last post by:
I've created an unmanaged C++ DLL and when I compile it I get numerous errors of the form xyz.cpp(nnn): warning C4273: '<somefunction>' : inconsistent dll linkage I have other DLLs that have...
2
by: jdlwright | last post by:
Hi, call me crazy (I'm thinking outside the box, breaking the mould, going beyond the envelope and so on and so on). What I would like to do is to be able to handle requests to the...
4
by: Bob | last post by:
Is it possible to have a DLL automatically include references to other DLL's that it depends upon when it is added to a project? Bob
6
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...
6
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...
4
by: mdubey82 | last post by:
While debugging my C code usind vs.net2005 I got warning C4273 what does it mean ?? And why I am getting this error ??? Warning 7 warning C4273: 'opj_create_decompress' : inconsistent dll...
3
by: Martin Schneider | last post by:
Hi! I'd like to use the numpy library (which runs on Python 2.5) in the same project with another (mandatory) library which needs python22.dll. When I try to compile I get an error similar to...
1
by: kurtzky | last post by:
I'm running a project and it doesn't any give any build errors. There' just a warning which says Warning: The dependency 'aaa' in project 'aaa' cannot be copied to the run directory because it would...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.