Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2005

Tip: Looking for answers? Try searching our database.

Inconsistent dll linkage??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Steele - 06 Feb 2005 04:45 GMT
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 been created using the same basic pattern. I
using the approach where the following code appears in the .h file:

#ifdef  MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif

Each of the functions in the .h file are prefixed with this macro:

MYDLL_API unsigned int myfunc();

The DLL project defines the MYDLL_EXPORTS symbol so that the specified
functions are exported. Conversely, any app that includes this .h file will
not have the macro defined and will use the dllimport directive.

So, this is my basic approach to creating my DLLs. In a couple of cases I'm
getting these warning messages. I'm obviously missing something obvious but
I can't figure it out. The DLLs appear to be working properly but I want to
get rid of these warnings. Any ideas?
Antti Keskinen - 06 Feb 2005 09:46 GMT
Hi !

This error happens when the linker is unsure what it should do with a
symbol. To export/import it or not. You should make sure that at the
beginning of the header file, you have a comment #pragma once written. This
makes sure that each function declaration is done only once, no matter how
many compilation units (.cpp files) include the header.

For example, this will cause the error
__declspec(dllexport) int MyFunc();
__declspec(dllimport) int MyFunc();    // Inconsistent DLL linkage

-Antti Keskinen

> I've created an unmanaged C++ DLL and when I compile it I get numerous
> errors of the form
[quoted text clipped - 22 lines]
> obvious but I can't figure it out. The DLLs appear to be working properly
> but I want to get rid of these warnings. Any ideas?
Peter Steele - 07 Feb 2005 15:23 GMT
This doesn't seem to be the cause in this case. I get these warnings when I
compile the DLL itself, not when I link it with other apps. The DLL of
course only includes its own .h file one time so there is no chance two
declspec directuves are being compiled, or at least I don't see how...

> Hi !
>
[quoted text clipped - 36 lines]
>> obvious but I can't figure it out. The DLLs appear to be working properly
>> but I want to get rid of these warnings. Any ideas?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.