Why create an include/ directory in C and C++ projects?

前端 未结 3 1060
挽巷
挽巷 2021-02-01 14:22

When I work on my personal C and C++ projects I usually put file.h and file.cpp in the same directory and then file.cpp can reference

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 14:37

    The main reason to do this is that compiled libraries need headers in order to be consumed by the eventual user. By convention, the contents of the include directory are the headers exposed for public consumption. The source directory may have headers for internal use, but those are not meant to be distributed with the compiled library.

    So when using the library, you link to the binary and add the library's include directory to your build system's header paths. Similarly, if you install your compiled library to a centralized location, you can tell which files need to be copied to the central location (the compiled binaries and the include directory) and which files don't (the source directory and so forth).

提交回复
热议问题