Skip to main content
GameDev.net gamedev.net
🔒 Locked

DLL Linkage warning

Started by jonbell Mar 7, 2006 at 2:40 PM 4 replies 2.4k views
Original Post
jonbell
jonbell
In my MFC I have overridden printf like this : in my header : extern "C" int printf(const char* szStr, ...); then in my cpp : extern "C" int printf(const char* szStr, ...) { } The code behaves as i would expect except that I get the following warning for every file that includes the header : warning C4273: 'printf' : inconsistent dll linkage How do i need to specify this to stop this warning?
moeron
moeron
it happens because you have different linkage for your version of printf. The original function is defined
extern "C" _CRTIMP int _cdecl printf( const char*, ... );

If your using a dll runtime library _CRTIMP is defined as __declspec dllimport). I was under the impression you can't override a C function, but I've been messing around in VC 6 and its letting me do it. However, I haven't been able to resolve this issue because if I make the function signature to be as follows
extern "C" __declspec(dllexport) int _cdecl printf( const char*, ... );

It still complains to me. Since I've edited this post and my previous one about 100 times in 10 minutes, I'm just going to leave the rest of the explaining up to the professionals =)
moe.ron
penwan
penwan
I'm not sure, but it may simply be that you are including your headers in the wrong order. Ex:

#include "MyPrintf.h"#include <cstdio>


Then the standard header's definition will override yours. Clearly its linking against yours if it's working as you expect. In this case switching the order of the headers (or simply not including the standard header) might work.
jonbell
jonbell
Its not the order of the headers. Has anyone solved this problem?
Yohumbus
Yohumbus
well I dont know much about the nature of the linking problem but a quick fix would just be to call the function something else and use macros to have all the other printf's reference your version. This seems like an ideal solution unless you are trying to do something tricky like have external libraries use your version. Anyway... good luck on it.
ASCII stupid question, get a stupid ANSI
jonbell
jonbell
My ocde compiles to a lib which is then called by another project so macro's are no good. Surely there is a way to get rid of this warning. Anyone?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.