tags:

views:

90

answers:

2

If a header file (.h) included in the source file has also been included in a static library (.lib), what will happen?

+1  A: 

I don't think anything will happen unless some objects have been instantiated in the header file:

i.e.:

CMyStringType superMansName("Clark Kent");

Will result in a link error where the object exists in both the static library and your code.

Lyndsey Ferguson
+2  A: 

A typical library implementation will include its own header, so this is not a particularly special case.

If the header declares things like global static variables, you of course can't define them more than once. Typically a library will include definitions for the data it declares (or, better, not declare any static global data) so your code that uses the library shouldn't duplicate those.

unwind
If the shared header declares constant variables like "const int A=100;", are there conflicts?
For int, that should work fine.
unwind
How about global non-static variable definition like "int A;"?
@unknown: Having that in the header file would be a problem. That's a definition, not a declaration. It should be "extern int A;", and then just a single definition (int A;) in the library implementation. This is how e.g. the "errno" interface is implemented.
unwind