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

后端 未结 4 912
独厮守ぢ
独厮守ぢ 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

    An obvious case is cross-compilation. GCC suffers a bit from a historical UNIX assumption that you're always compiling for your local system, or at least something that's very close. That's why the compiler's header files are in the system root. The clean interface is missing.

    In comparison, Windows assumes no compiler, and Windows compilers do not assume you're targeting the local system. That's why you can have a set of compilers and a set of SDK's installed.

    Now in cross-compilation, GCC behaves much more like a compiler for Windows. It no longer assumes that you intend to use the local system headers, but lets you specify exactly which headers you want. And obviously, the same then goes for the libraries you link in.

    Now note that when you do this, the set of replacement headers is designed to go on top of the base system. You can leave out headers in the replacement set if their implementation would be identical. E.g. chances are that is the same. There's not that much variation in complex number implementations. However, you can't randomly replace internal implementation bits like .

    TL,DR : this option if for people who know what they're doing. "Being unsafe" is not an argument for the target audience.

提交回复
热议问题