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
2009-10-27 12:44:36
+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
2009-10-27 12:46:15
If the shared header declares constant variables like "const int A=100;", are there conflicts?
2009-10-27 12:54:40
For int, that should work fine.
unwind
2009-10-27 13:00:30
How about global non-static variable definition like "int A;"?
2009-10-27 13:04:10
@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
2009-10-27 13:57:46