472,982 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,982 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 31445
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.