Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang++ not seeing libc++

Tags:

c++

clang++

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?

like image 985
dak Avatar asked Nov 16 '22 15:11

dak


1 Answers

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
like image 62
Benoit Blanchon Avatar answered Dec 05 '22 11:12

Benoit Blanchon