代码之家  ›  专栏  ›  技术社区  ›  doraemon

clang++无法编译hello world

  •  -2
  • doraemon  · 技术社区  · 7 年前

    我和GCC一起在康达环境中安装了Clang。他们的版本是

    gcc     7.2.0
    clang   7.0.0
    libcxx  7.0.0
    

    然后我创建了一个 hello world SRC文件 a.cpp

    1. 如果我用 clang++ a.cpp . 错误读取

      a.cpp:1:10: fatal error: 'iostream' file not found
      #include <iostream>
               ^~~~~~~~~~
      1 error generated.
      
    2. 使用 clang++ a.cpp --stdlib=libstdc++ ,错误相同

    3. 使用 clang++ a.cpp --stdlib=libc++ ,错误变成

      ~/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)
      
    4. 使用 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.
      

    我使用共享计算机,因此无法安装系统范围的编译器和头文件。

    问题:

    1. 我该怎么做才能让它工作?
    2. 如果 clang 不附带自己的头文件,我需要使用提供的 gcc ,我应该考虑 clang version 以及 gcc version ?
    3. 我需要安装吗 libc++ 在相同的康达环境中使用 clang++ ?

    经过一些测试,我在Conda中找到了解决方法,这是作为答案发布的。不过,我还是不明白 铿锵声 工作,尤其是与 海湾合作委员会 .如果有人能回答(我会接受这一点作为对本帖的回答),我将不胜感激:

    1. 铿锵声 将所有作业转发到 海湾合作委员会 所以我们总是需要 海湾合作委员会 安装工具链以便使用 铿锵声 是吗?
    2. 我找到了一个包含文件夹 铿锵声 ,这就是 $HOME/conda/envs/test/include/c++/v1 旁边 $HOME/conda/envs/test/include/c++/7.2.0 这是来自 海湾合作委员会 . 但是如果 --gcc-toolchain 已指定,则 v1 未搜索文件夹中的标题(可通过添加 -v 到编译器。那么它的用法是什么 V1 包括文件吗?
    1 回复  |  直到 7 年前
        1
  •  1
  •   doraemon    7 年前

    最后我找到了方法,那就是

    clang++ --gcc-toolchain=$HOME/conda/envs/test a.cpp
    

    这一点也不明显。