C++ Clang 看不到基本标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26333823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:35:19  来源:igfitidea点击:

Clang doesn't see basic headers

c++c++11clangclang++llvm-clang

提问by sweet_sugar

I've tried to compile simple hello world on Fedora 20 with Clang, and I get the following output:

我尝试使用 Clang 在 Fedora 20 上编译简单的 hello world,得到以下输出:

d.cpp:1:10: fatal error: 'iostream' file not found

#include <iostream>

d.cpp:1:10: 致命错误:找不到“iostream”文件

#include <iostream>

I don't have any idea how to resolve it.

我不知道如何解决它。

采纳答案by user4823890

Point 3solved the problem for me.

第 3 点为我解决了问题。

1. Had the same issue, fedora 21::clang 3.5.0:

1. 有同样的问题,fedora 21::clang 3.5.0:

clang++ -std=c++14 -pedantic -Wall test_01.cpp -o test_01 -v

2.

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>

3.

3.

sudo yum install gcc-c++

4.

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.

回答by ArunasR

This is because g++ is not installed, so libstdc++ is not present.

这是因为没有安装 g++,所以不存在 libstdc++。

You can install g++, or if LLVM is preferred, install LLVM libc++ and specify that you want to use it, like so:

您可以安装 g++,或者如果首选 LLVM,请安装 LLVM libc++ 并指定您要使用它,如下所示:

sudo apt-get install libc++-dev
clang++ -stdlib=libc++ <rest of arguments>

You may wish to link /usr/bin/c++ to the default compiler:

您可能希望将 /usr/bin/c++ 链接到默认编译器:

ln -s /usr/bin/c++ /usr/bin/clang++-libc++

and then compile simply using

然后简单地使用编译

$ c++ <args_as_usual>

回答by Stepan Dyatkovskiy

Looks like you should provide your clang build with -stdlib option. One of -stdlib=libc++ or -stdlib=libstdc++ will probably work. There are more details on your subject:

看起来您应该为您的 clang 构建提供 -stdlib 选项。-stdlib=libc++ 或 -stdlib=libstdc++ 之一可能会起作用。有关您的主题的更多详细信息:

When is it necessary to use the flag -stdlib=libstdc++?

什么时候需要使用标志 -stdlib=libstdc++?

回答by eyesfree

-stdlib=libstdc++ solved it for me. Here is my complete tasks.json config:

-stdlib=libstdc++ 为我解决了它。这是我完整的 tasks.json 配置:

{
"tasks": [
    {
        "type": "shell",
        "label": "clang++ build active file",
        "command": "clang++",
        "args": [
            "-std=c++11",
            "-stdlib=libstdc++",
            "hello.cpp",
            "-o",
            "hello.out",
            "--debug"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
],
"version": "2.0.0"