Question

Clang’s documentation mentions the availability of a flag called --system-header-prefix.

The idea being that all included headers matching this prefix will be treated as system headers, and not generate warnings.

I’d like to use this flag instead of including those headers using -isystem instead of -I.

Background

I happen to have a (new) project that depends on a couple of legacy libraries, but which itself has really strict warning settings, and treats those warnings as errors. The result is (not too surprisingly) a project that doesn’t build because of the warnings that are generated by the headers of the included legacy–library.

The idea was to use --system-header-prefix=legacyLib/ in Xcode’s OTHER_CFLAGS build setting.

If I do this, however, clang gives me the following error message:

clang: error: unsupported option '--system-header-prefix=legacyLib/'

I am using Version 5.1.1 (5B1008) — i.e. the current public release.

The output of clang --version is

clang --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Was it helpful?

Solution

You are referring to Clang 3.5 documentation. In Clang 3.4 User's Manual this option is called -isystem-prefix. The option was renamed to --system-header-prefix in r204775, 2.5 months after 3.4 release.

So you have to use -isystem-prefix option, but it's not explained that it's cc1 option, so you have to use it like

clang -I ./nested -Xclang -isystem-prefix -Xclang legacyLib/ test.c

-Xclang is used to pass the next option to cc1. By the way, I've noticed that warnings aren't suppressed if legacyLib/ is in the same directory as test.c. I don't know if it's a bug, but if you disagree with me, please file a bug report. The previous command works with the following directory structure

<working directory>
|- test.c, which has #include "legacyLib/header.h"
`- nested/
   `- legacyLib/
      `- header.h, which has warnings

For the future reference, Clang 3.5 supports --system-header-prefix, i.e. the following command works (checked with clang version 3.5.0 (trunk 207361))

clang -I ./nested --system-header-prefix legacyLib/ test.c
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top