Why do projects use the -I include switch given the dangers?

后端 未结 4 962
独厮守ぢ
独厮守ぢ 2021-02-01 15:20

Reading the fine print of the -I switch in GCC, I\'m rather shocked to find that using it on the command line overrides system includes. From the preprocessor docs

4条回答
  •  不要未来只要你来
    2021-02-01 15:43

    What legitimate reasons are there for -I over -iquote? -I is standardized (at least by POSIX) while -iquote isn't. (Practically, I'm using -I because tinycc (one of the compilers I want my project to compile with) doesn't support -iquote.)

    How do projects manage with -I given the dangers? You'd have the includes wrapped in a directory and use -I to add the directory containing that directory.

    • filesystem: includes/mylib/endian.h
    • command line: -Iincludes
    • C/C++ file: #include "mylib/endian.h" //or

    With that, as long as you don't clash on the mylib name, you don't clash (at least as far header names are concerned).

提交回复
热议问题