user197306
user197306

Reputation:

Using the same header files as those in static library

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

Upvotes: 0

Views: 203

Answers (2)

unwind
unwind

Reputation: 400109

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.

Upvotes: 2

Lyndsey Ferguson
Lyndsey Ferguson

Reputation: 5384

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.

Upvotes: 1

Related Questions