I installed clang in my conda environment along with gcc. Their versions are
gcc 7.2.0
clang 7.0.0
libcxx 7.0.0
I then created an hello world src file a.cpp
If I compile the file using
clang++ a.cpp
. The error readsa.cpp:1:10: fatal error: 'iostream' file not found #include <iostream> ^~~~~~~~~~ 1 error generated.
Using
clang++ a.cpp --stdlib=libstdc++
, the error is the sameUsing
clang++ a.cpp --stdlib=libc++
, the error becomes~/conda/envs/test/bin/ld: cannot find crtbegin.o: No such file or directory ~/conda/envs/test/bin/ld: cannot find -lgcc clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
Using
clang++ a.cpp -I$HOME/conda/envs/test/include/c++/7.2.0
In file included from a.cpp:1: /site/home/shliu/conda/envs/test/include/c++/7.2.0/iostream:38:10: fatal error: 'bits/c++config.h' file not found #include <bits/c++config.h> ^~~~~~~~~~~~~~~~~~ 1 error generated.
I use a shared computer so I cannot install system wide compilers and header files.
Questions:
- What should I do to have it work?
- If
clang
does not ship with its own header files and I need to use what are provided bygcc
, should I consider the compatibility ofclang version
and thegcc version
? - Do I need to install
libc++
in the same conda environment in order to useclang++
?
After some test, I found the way to do it in conda, which is posted as the an answer. However, I still don't understand how clang
works, especially its relation with gcc
. I would appreciate it very much if any one could answer (and I will accept that as the answer to this post):
- Does
clang
forward all the jobs togcc
so we always need thegcc
tool chain to be installed in order to useclang
? - I found an include folder for
clang
, which is$HOME/conda/envs/test/include/c++/v1
alongside with$HOME/conda/envs/test/include/c++/7.2.0
which is fromgcc
. But if the--gcc-toolchain
has been specified, thev1
folder is not searched for headers, (which can be seen from the output by adding-v
to the compiler. Then what is the usage of thev1
include files?