473,396 Members | 2,108 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,396 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 6056
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
35
by: Francine.Neary | last post by:
I'm finding it really hard to keep some of these things straight... For example, fputs is to puts as fprintf is to printf, except that fputs has the file handle at the end and fprintf at the...
12
by: Taras_96 | last post by:
Hi everyone, AFAIK external linkage allows you to refer to variables/functions outside of the current translation unit. A variable in an unnamed namespace is similar to declaring a static...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.