[cfe-dev] clang-check doesn't find C++ headers with -stdlib=libc++ option

Riyaz Puthiyapurayil via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 24 22:07:12 PDT 2018


Forgot to mention the platform is Linux. I found where clang++ automatically detects the C++ include path for libc++:

Driver/ToolChains/Linux.cpp:

DetectLibcxxIncludePath

Not sure if this ever gets invoked from clang-check driver.

/Riyaz

From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of Riyaz Puthiyapurayil via cfe-dev
Sent: Tuesday, April 24, 2018 8:24 PM
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] clang-check doesn't find C++ headers with -stdlib=libc++ option

I have clang, clang-check, libc++, libc++abi, etc. installed in a tree rooted in a non-standard location. The directory structure looks like this:

$CLANG_ROOT
|_bin
| |_ clang
| |_ clang-check
| |...
|
|_include
| |_ various built-in C header files
| |_c++
|   |_v1
|     |_ various libc++ header files
|_lib -> lib64
|_lib64
  |_ various libraries

Note that the above directory structure is standard, only the root directory is in a non-standard location. A simple C++ file like this:


// /tmp/fill.cpp
#include <algorithm>
#include <vector>
std::vector<int>  v{1, 2, 3};
int main() {
    std::fill(v.begin(), v.end(), -1);
    return 0;
}

compiles fine with clang++:

$ clang++ -std=c++11 -stdlib=libc++ /tmp/fill.cpp
$

But with clang-check, it doesn't compile fine even though compile_commands.json has the exact same clang "command". Even specifying -stdlib=libc++ on the command line doesn't work:

$ clang-check /tmp/fill.cpp -- -stdlib=libc++ -std=c++11 -xc++
/tmp/fill.cpp:1:10: fatal error: 'algorithm' file not found
#include <algorithm>
         ^~~~~~~~~~~
1 error generated.
Error while processing /tmp/fill.cpp.
$

But the following works:

$ clang-check /tmp/fill.cpp -- -std=c++11 -cxx-isystem ${CLANG_ROOT}/include/c++/v1
$

Why is clang-check not automatically inferring libc++ header paths the same way clang++ driver finds them? Is there some build configuration that can make clang tools find libc++ headers automatically when -stdlib=libc++ is specified.

BTW, clang-check finds libstdc++ headers if -gcc-toolchain option is specified.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180425/87eaf40b/attachment-0001.html>


More information about the cfe-dev mailing list