swe*_*gar 46 c++ clang llvm-clang c++11 clang++
我试图用Clang在Fedora 20上编译简单的hello world,我得到以下输出:
d.cpp:1:10:致命错误:找不到'iostream'文件
#include <iostream>
我不知道如何解决它.
小智 54
原因之一可能是:clang 没有自己的 c++ 头库,因此它指向 gcc 的库文件夹来访问头文件。您可以使用命令查看并确认
clang -v
Run Code Online (Sandbox Code Playgroud)
这将打印其版本和所选的 gcc 安装,这将帮助您了解它正在使用哪个版本的 gcc。对我来说,
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
Run Code Online (Sandbox Code Playgroud)
现在可以看到它选择了我没有安装的 gcc 第 12 版本,因此出现错误,因为它找不到它(不知道它是如何选择该版本的,即使我还没有安装它) 。但解决办法是安装g++ nth版本。您可以通过以下命令来完成此操作,其中 n 是 gcc 选择的版本号,您就可以开始了。
sudo apt install g++-n
Run Code Online (Sandbox Code Playgroud)
经过大量挖掘后我得到了这个答案,并发现了这个博客clangmissingheaders
Aru*_*asR 33
这是因为没有安装g ++,所以libstdc ++不存在.
您可以安装g ++,或者如果首选LLVM,请安装LLVM libc ++并指定您要使用它,如下所示:
sudo apt-get install libc++-dev
clang++ -stdlib=libc++ <rest of arguments>
Run Code Online (Sandbox Code Playgroud)
您可能希望将/ usr/bin/c ++链接到默认编译器:
ln -s /usr/bin/c++ /usr/bin/clang++-libc++
Run Code Online (Sandbox Code Playgroud)
然后简单地使用编译
$ c++ <args_as_usual>
Run Code Online (Sandbox Code Playgroud)
小智 15
第3点为我解决了这个问题.
1.有同样的问题,fedora 21 :: clang 3.5.0:
clang++ -std=c++14 -pedantic -Wall test_01.cpp -o test_01 -v
Run Code Online (Sandbox Code Playgroud)
2.
ignoring nonexistent directory "/usr/lib/gcc/i686-redhat-linux/4.9.2/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/bin/../lib/clang/3.5.0/include
/usr/include
End of search list.
test_01.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
Run Code Online (Sandbox Code Playgroud)
3.
sudo yum install gcc-c++
Run Code Online (Sandbox Code Playgroud)
4.
#include "..." search starts here:
#include <...> search starts here:
/bin/../lib/gcc/i686-redhat-linux/4.9.2/../../../../include/c++/4.9.2
/bin/../lib/gcc/i686-redhat-linux/4.9.2/../../../../include/c++/4.9.2/i686-redhat-linux
/bin/../lib/gcc/i686-redhat-linux/4.9.2/../../../../include/c++/4.9.2/backward
/usr/local/include
/usr/bin/../lib/clang/3.5.0/include
/usr/include
/usr/lib/gcc/i686-redhat-linux/4.9.2/include
End of search list.
Run Code Online (Sandbox Code Playgroud)
Bog*_*ogi 15
就我而言,clang 使用的是 GCC 安装版本 12,但我缺少libstdc++
该版本的:
$ clang -v
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Run Code Online (Sandbox Code Playgroud)
像这样修复它:
sudo apt install libstdc++-12-dev
Run Code Online (Sandbox Code Playgroud)
看起来您应该为您的 clang 构建提供-stdlib
选项。其中之一-stdlib=libc++
或-stdlib=libstdc++
可能会起作用。
有关您的主题的更多详细信息:
归档时间: |
|
查看次数: |
62744 次 |
最近记录: |