views:

74

answers:

2

XYZ.dll defines a global variable int x. ABC.c also defines the same global variable int x. How can one link XYZ.dll to ABC.exe? How is this conflict in global namespace resolved?

A: 

This is a really good question, and I hope it gets a real answer. From what I can gather, a "global" symbol from a dll would have to be explictly imported via an associated header file. If you have two symbols that are the same, whichever symbol gets defined last, in the c file, is the one that would take precedence. That is, if you have ABC.c, and at the top, you would import XYZ.h, and then define int x. You either clobber the int x from XYZ.h, or you get a compile time error.

Breton
A: 

The variable int x has to be declared as extern int x in the header file of XYZ . And where ever you are going to use this variable just declare this variable. Like in ABC.c in the global space declare this variable like int x;

sameer karjatkar