Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weak linking in MSVC C++

Status
Not open for further replies.

ArtIsFun

Programmer
Joined
Mar 18, 2003
Messages
1
Location
US
Weak linking (if I'm using the term correctly) is the ability to specify the implementation of a routine twice and have the weakly-linked copy be replaced by the strongly-linked copy. I've used it in gcc and recently stumbled across weak linking in MSVC but I can't find documentation or the compiler switches that enable or disable it.

Consider the example below using printf from <stdio.h>. In this code snippet, the standard printf is replaced with a no-op. You might examine doing this if you link to a library which outputs lots of debugging that you want to turn off, and you don't have access to the source code:

#include <stdio.h>

int __cdecl printf(const char* format, ...)
{
((void*)format);
return 0;
}

int main()
{
printf(&quot;hello, world\n&quot;);
return 0;
}

I compiled and ran this in both C++ and C using the default (Win32 Debug) project settings and received no errors or warnings. Running it gives the expected result: a no-op.

Has anyone else done this? Does anyone know where/if this behavior is documented, and which linker switches control it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top