在Clang ++中找到iostream:致命错误:找不到"iostream"文件 [英] Locating iostream in Clang++: fatal error: 'iostream' file not found

查看:3160
本文介绍了在Clang ++中找到iostream:致命错误:找不到"iostream"文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下简单的C ++程序:

I wrote the following simple C++ program:

#include <iostream>

using namespace std;

int main() {
    cout << "Hello, World" << endl;
    return 0;
}

当我使用g ++进行编译时,它可以完美地工作.当我尝试使用Clang ++进行编译时,出现以下错误:

When I compile this with g++, it works perfectly. When I try to compile with Clang++, I get the following error:

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

使用-v参数运行,我看到以下内容:

Running with the -v parameter, I see the following:

ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/backward"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/6.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++
 /usr/include/clang/6.0.0/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

分别查看这些文件夹,发现在/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++(或更简而言之,在/usr/include/c++)中,我具有以下目录:

Looking into these folders individually, I found that in /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++ (or, more concisely, in /usr/include/c++) I have the following directories:

drwxr-xr-x   5 root root 4.0K Feb  4 09:38 .
drwxr-xr-x 101 root root  20K Feb  4 12:22 ..
drwxr-xr-x  12 root root  12K May 24  2018 5
drwxr-xr-x  12 root root  12K Oct  9 14:53 7
drwxr-xr-x   5 root root 4.0K Feb  4 09:38 v1
lrwxrwxrwx   1 root root    1 Apr 11  2018 5.5.0 -> 5
lrwxrwxrwx   1 root root    1 Apr 15  2018 7.3.0 -> 7

57v1目录中的每个目录中都有一个名为iostream

Within each of the 5, 7, and v1 directories there exists a file called iostream

/usr/include/x86_64-linux-gnu中还存在一个c++目录,该目录看起来与此完全相同(具有575.5.07.3.0目录).

Also in /usr/include/x86_64-linux-gnu there exists a c++ directory which looks exactly like this one (with 5, 7, 5.5.0, and 7.3.0 directories).

/usr/include中还存在一个c++目录,该目录与上面的两个目录完全一样

Also in /usr/include there exists a c++ directory which looks exactly like the two above

我不确定我的开发环境如何变得如此混乱,但是在这一点上,我只想知道如何解决它,以便Clang ++将成功找到iostream的这9个实例之一,而不是抛出不存在的错误.我是否需要添加一个环境变量来告诉Clang在哪里看?我是否需要传递命令行参数来告诉Clang递归搜索?

I'm not sure how my dev environment became such a mess, but at this point I would just like to know how to fix it so that Clang++ will successfully find one of these 9 instances of iostream instead of throwing an error that it doesn't exist. Do I need to add an environment variable to tell Clang where to look? Do I need to pass a command-line parameter to tell Clang to search recursively?

当我尝试使用libc++构建时,出现以下错误:

When I try building with libc++ I get the following error:

$> clang++ -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++abi
clang: error: linker command failed with exit code 1 (use -v to see invocation)

当我尝试使用手动覆盖的包含路径进行构建时,出现以下错误:

When I try building with the include path manually overridden, I get the following error:

$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 main.cpp
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)

当我同时尝试这两种方法时,会出现以下(非常大的)错误:

When I try both, I get the following (incredibly large) error:

$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
In file included from /usr/include/c++/7/cstdlib:77:
/usr/include/c++/7/bits/std_abs.h:56:3: error: declaration conflicts with target of using declaration already in scope
  abs(long __i) { return __builtin_labs(__i); }
  ^
/usr/include/c++/v1/stdlib.h:111:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long      abs(     long __x) _NOEXCEPT {return  labs(__x);}
                                           ^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
  using ::abs;
          ^
/usr/include/c++/7/bits/std_abs.h:61:3: error: declaration conflicts with target of using declaration already in scope
  abs(long long __x) { return __builtin_llabs (__x); }
  ^
/usr/include/c++/v1/stdlib.h:113:44: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);}
                                           ^
/usr/include/c++/7/bits/std_abs.h:52:11: note: using declaration
  using ::abs;
          ^
In file included from main.cpp:1:
In file included from /usr/include/c++/7/iostream:39:
In file included from /usr/include/c++/7/ostream:38:
In file included from /usr/include/c++/7/ios:42:
In file included from /usr/include/c++/7/bits/ios_base.h:41:
In file included from /usr/include/c++/7/bits/locale_classes.h:40:
In file included from /usr/include/c++/7/string:52:
In file included from /usr/include/c++/7/bits/basic_string.h:6352:
In file included from /usr/include/c++/7/ext/string_conversions.h:41:
/usr/include/c++/7/cstdlib:177:3: error: declaration conflicts with target of using declaration already in scope
  div(long __i, long __j) { return ldiv(__i, __j); }
  ^
/usr/include/c++/v1/stdlib.h:116:42: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY  ldiv_t div(     long __x,      long __y) _NOEXCEPT {return  ldiv(__x, __y);}
                                         ^
/usr/include/c++/7/cstdlib:145:11: note: using declaration
  using ::div;
          ^

提醒一下,我只是在尝试编译Hello,World

我还尝试使用以下命令卸载并重新安装Clang:

I also tried uninstalling and re-installing Clang with the following command:

$> sudo apt-get purge --auto-remove clang
$> sudo apt-get update
$> sudo apt-get install clang

这没有效果.我正在运行Ubuntu 18.04,我不知道出了什么问题或从哪里开始修复它.我的构建环境一片混乱.

This had no effect. I'm running Ubuntu 18.04 and I have no idea what's wrong or where to start with fixing it. My build environment is in shambles.

如果可能的话,我想让Clang正常工作,而不是退一步使用G ++,因为我的IDE似乎正在自动检测Clang并将其用于语法检查.这意味着我编写的每个C ++程序在第一行都有一个致命错误(找不到iostream"),并且文件的其余部分都未被检查,因为第一个是致命错误.

If possible I would like to get Clang working instead of falling back to using G++, because my IDE seems to be automatically detecting Clang and using it for syntax checking. This means that every C++ program I've written has one fatal error on line one ("iostream not found") and the rest of the file goes unchecked because that first one is a fatal error.

我尝试从Ubuntu apt仓库中安装更多软件包,但是没有运气:

I've tried installing a few more packages from the Ubuntu apt repository with no luck:

$> sudo apt-get install libc++1 libc++1-9 libc++abi1 libc++abi1-9 llvm-9 llvm-9-dev
$> clang++ -isystem /usr/include/c++/7 -isystem /usr/include/x86_64-linux-gnu/c++/7 -stdlib=libc++ main.cpp
/usr/bin/ld: cannot find -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我还尝试过sudo apt-get install lc++1,只是发现这是一个 完全不相关 的软件包.

I also tried sudo apt-get install lc++1 only to find this is an entirely unrelated package.

我花了几个小时来解决这个问题,从apt和从源安装了多个软件包,尝试了各种版本的各种工具,从其他来源手动复制了库,甚至跳到了Clang IRC上并与几个直接有经验的开发人员.

I spent several more hours trying to resolve this, installing multiple packages both from apt and from source, trying different versions of various tools, manually copying in libraries from other sources, and even hopped onto the Clang IRC and spoke to several very knowledgeable developers directly.

没有人能够弄清楚笔记本电脑出了什么问题,而且我什么也没能使它正常工作.

No one was able to figure out what's wrong with my laptop, and nothing I did ever got it working.

不幸的是,我将在另外两周内再也没有这款笔记本电脑,所以我很可能需要解决此问题,因为无法复制"-因为一旦笔记本电脑用完,我将无法复制损坏的开发环境

Unfortunately I won't still have this laptop in another two weeks, so I'll likely need to close this issue as "cannot reproduce" - because once the laptop is gone I will have no way of replicating the broken development environment.

推荐答案

我也为此问题困扰了很长时间.您应该尝试删除该文件夹(cd/usr/lib/gcc/aarch64-linux- gnu/8). clang ++无法正常工作的原因是此文件夹不包含libstdc ++.a.

I have also been troubled by this problem for a long time.You should try to delete the folder(cd /usr/lib/gcc/aarch64-linux-gnu/8). The reason why clang++ can't work is this folder doesn't contain libstdc++.a.

clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/7.3.0
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.3.0

检查/usr/lib/gcc/aarch64-linux-gnu/中的所有文件夹 clang ++将选择最后一个,请确保最后一个存在libstdc ++.a

check all the folders in /usr/lib/gcc/aarch64-linux-gnu/ clang++ will choose the last one,make sure there is the libstdc++.a in the last one

这篇关于在Clang ++中找到iostream:致命错误:找不到"iostream"文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆