gpt4 book ai didi

c++ - Clang++ 看不到 libc++

转载 作者:行者123 更新时间:2023-12-03 17:30:40 27 4
gpt4 key购买 nike

我刚刚从 https://github.com/llvm/llvm-project.git 安装了 clang++ 和 libc++ .尝试运行时:

clang main.cpp -stdlib=libc++ -lc++abi

哪里 main.cpp :
#include <iostream>

int main() {
std::cout << "main>" << std::endl;
}

我收到一个错误:
main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
-v选项的输出:
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.

它可能与包含有关。我安装了 libc++/usr/include (例如, iostream 可以在 /usr/include/c++/6/iostream 找到)。有没有办法让 clang 知道文件( iostream 不是它提示的唯一标题)在哪里?

最佳答案

我通过将正确的目录添加到包含搜索路径来解决类似的问题。
此目录必须与 libc++ 的版本匹配。
例如,如果您安装了软件包 libc++10-dev ,您必须添加 /usr/lib/llvm-10/include/c++/v1/ .
这是调用:

clang main.cpp -stdlib=libc++ -I/usr/lib/llvm-10/include/c++/v1/
如果您不确定要使用哪个文件夹,可以使用 find找到它:
$ 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

关于c++ - Clang++ 看不到 libc++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54728961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com