Clang++ not seeing libc++
Asked Answered
W

1

6

I've just installed clang++ and libc++ from https://github.com/llvm/llvm-project.git. While trying to run:

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

where main.cpp:

#include <iostream>

int main() {
    std::cout << "main>" << std::endl;
}

I get an error:

main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>

-v option's output:

clang version 9.0.0 (https://github.com/llvm/llvm-project.git 40046bc8430f0b90d76cef9e6cc62ccc2abcb0b0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/jakub/Documents/Programming/Projects/TraitNet/src -ferror-limit 19 -fmessage-length 93 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/main-48c930.o -x c++ main.cpp -faddrsig
clang -cc1 version 9.0.0 based upon LLVM 9.0.0svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/lib/clang/9.0.0/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.

It probably has to do with the includes. I installed libc++ to /usr/include (eg. iostream could be found at /usr/include/c++/6/iostream). Is there a way of letting clang know where the files (iostream is not the only header it has complained about) are?

Wiegand answered 17/2, 2019 at 0:18 Comment(2)
Possible duplicate of Clang doesn't see basic headersCrazyweed
Aka try: sudo apt-get install libc++-dev and then ln -s /usr/bin/c++ /usr/bin/clang++-libc++ and then just clang++ to compile normally. Unsure how your system is setup.Crazyweed
T
2

I fixed a similar issue by adding the right directory to the include search path.

This directory must match the version of libc++. For example, if you installed the package libc++10-dev, you must add /usr/lib/llvm-10/include/c++/v1/.

Here is the invocation:

clang main.cpp -stdlib=libc++ -I/usr/lib/llvm-10/include/c++/v1/

If you're unsure what folder to use, you can use find to locate it:

$ find /usr/ -name iostream
/usr/include/c++/5/iostream
/usr/include/c++/7/iostream
/usr/include/c++/4.4/iostream
/usr/include/c++/8/iostream
/usr/include/c++/4.9/iostream
/usr/include/c++/10/iostream
/usr/include/c++/9/iostream
/usr/include/c++/4.8/iostream
/usr/include/c++/4.7/iostream
/usr/include/c++/4.6/iostream
/usr/lib/llvm-10/include/c++/v1/iostream
Tisiphone answered 16/5, 2021 at 9:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.