0

If a library project defines some variables and utility functions in its stdafx.h/cpp, will these be visible throughout application projects built on top of the library?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

2 Answers2

3

Yes and no, they need to be exported just as anything else. Precompiled headers are there to speed up compilation, they do not affect the produced executable/library.

alain
  • 11,939
  • 2
  • 31
  • 51
  • My confusion is that clearly I don't `#include "stdafx.h"` for the library file's header in the application. But Library headers that get included in the application _can_ see those vars. – Mr. Boy Aug 05 '15 at 15:31
  • Does "can see those vars" mean it compiles and links correctly if you use them in the application? Or is it just that intellisense is seeing them? – alain Aug 05 '15 at 15:37
1

No, it is an implementation detail for the library project only. And in general it does not contain declarations that are exposed by the library, they are exposed by a .h file that was meant to be #included in your own project's source files. The library's stdafx.h may include that .h file as well, it isn't very common.

You use your own precompiled header, if you want to #include the library's .h file(s) then that's up to you. Useful only if you use the library declarations in multiple source files of your own project and the library is stable.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536