0

I would like to make my header file header.h be able to be included like this: #include <header.h> in every location.

I'm using XCode on macOS.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ofsho
  • 161
  • 1
  • 1
  • 5
  • Put it in `/usr/local/include` — probably. – Jonathan Leffler Oct 14 '20 at 17:57
  • The answer to your question is compiler and OS specific. The best solution would be to use compiler options (often `-I`) to add the directory containing the header to the compiler include path. Another not as good solution would be to put the header in a system include directory, (like `/usr/include` on a Linux/Unix system). – pcarter Oct 14 '20 at 17:58
  • @pcarter: The OS is macOS from the tags; that probably means the compiler is Clang from XCode. Modifying `/usr/include` is probably not an option on macOS — in fact, that directory (`/usr/include`) doesn't even exist on macOS Catalina 10.15.x. – Jonathan Leffler Oct 14 '20 at 17:59
  • Does this answer your question? [How to add a global include path for xcode](https://stackoverflow.com/questions/749027/how-to-add-a-global-include-path-for-xcode) – rustyx Oct 14 '20 at 18:01

1 Answers1

0

For Xcode you will want to add the path containing the headers to SYSTEM_HEADER_SEARCH_PATHS (or "System Header Search Paths") either in yout Xcconfig or Xproj file. However it is porbably better to just user User header paths and #include "header.h" cause using angle brackets is usually meant for system headers so using them for user header files could be confusing.

Garrigan Stafford
  • 1,331
  • 9
  • 20
  • 1
    Are you sure they're looking for a pre-compiled header? They're more of a menace than a benefit AFAIAC, but YMMV, as they say. – Jonathan Leffler Oct 14 '20 at 17:58
  • I can see how they can cause issues. I think the big thing is to ensure that the files do need to be included effectively everywhere, say like a logging utility header, and that the header code in the PCH is mostly independent and isolated. Also have to be careful that you write the header to be order invariant and with gurads. But thats just general header stuff – Garrigan Stafford Oct 14 '20 at 18:01
  • I am pretty sure the question is about include path, not PCH. – DevSolar Oct 14 '20 at 18:02
  • I kinda see it as both. Being able to use <> and being able to include it everywhere. However, I see how I could be misreading it. – Garrigan Stafford Oct 14 '20 at 18:05
  • How does "being able to include it everywhere" relate to PCH? – DevSolar Oct 14 '20 at 18:08