471,092 Members | 996 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Inconsistent dll linkage??

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?
Nov 17 '05 #1
1 5595
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

"Peter Steele" <ps*****@z-force.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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?

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by qazmlp | last post: by
47 posts views Thread by Richard Hayden | last post: by
20 posts views Thread by Grumble | last post: by
10 posts views Thread by Mark A. Gibbs | last post: by
5 posts views Thread by pembed2003 | last post: by
3 posts views Thread by al.cpwn | last post: by
13 posts views Thread by fctk | last post: by
35 posts views Thread by Francine.Neary | last post: by
12 posts views Thread by Taras_96 | last post: by

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.