include-what-you-use / include-what-you-use

A tool for use with clang to analyze #includes in C and C++ source files
https://include-what-you-use.org
Other
4.09k stars 388 forks source link

Support both c++ standard libraries #895

Open darkdragon-001 opened 3 years ago

darkdragon-001 commented 3 years ago

I am using Ubuntu 21.04 with clang libc++-dev and iwyu package.

While I can build via

clang++ -stdlib=libc++ main.cpp

I cannot

include-what-you-use -stdlib=libc++ main.cpp

because of

In file included from main.cpp:1:
include/lib/lib.h:3:10: fatal error: 'string' file not found
#include <string>
         ^~~~~~~~

It resides in /usr/lib/llvm-11/include/c++/v1/. Adding -I/usr/lib/llvm-11/include/c++/v1 explicitly solves the problem. I think this should not be necessary as clang++ is capable of resolving it itself as well.

Might be related to #100

kimgr commented 3 years ago

I'm guessing include-what-you-use is not installed in the same directory as clang?

I think the Clang code IWYU uses bases its search path on the executable path (that's basically incorrect, but convenient), so if they're in different roots, well, it's not going to work.

darkdragon-001 commented 3 years ago

Both are installed with prefix /usr as installed from Ubuntu repositories via apt. So they should have exactly the same executable path...

kimgr commented 3 years ago

What does which include-what-you-use and which clang (possibly with version suffix, e.g. clang-10) say on your system?

darkdragon-001 commented 3 years ago
$ which clang
/usr/bin/clang
$ which include-what-you-use
/usr/bin/include-what-you-use
lrwxrwxrwx. 1 root root   24 Jan 14 15:39 /usr/bin/clang -> ../lib/llvm-11/bin/clang
lrwxrwxrwx. 1 root root   26 Jan 14 15:39 /usr/bin/clang++ -> ../lib/llvm-11/bin/clang++
lrwxrwxrwx. 1 root root   26 Jan  6 19:16 /usr/bin/clang++-11 -> ../lib/llvm-11/bin/clang++
lrwxrwxrwx. 1 root root   24 Jan  6 19:16 /usr/bin/clang-11 -> ../lib/llvm-11/bin/clang
kimgr commented 3 years ago

Could you try putting include-what-you-use in /usr/lib/llvm-11/bin/ and make the one in /usr/bin a symlink, like clang?

I'm curious if that "fixes" this, because then it's definitely a case of issue 100 again.