没有GCC或MSVC的Clang

时间:2019-06-05 21:44:23

标签: c++ clang

我想在Linux上没有GCC且在Windows上没有MSVC的情况下使用clang。我的理解是,由于以下原因,这在过去是不可能的:

  1. 没有LLVM链接器。
  2. 没有兼容的STL。

但是,我的印象是v8.0.0应该可以实现,因为现在有了viable linker和兼容的STL library

不幸的是,在执行这种情况时,我在Linux和Windows上遇到了不同的错误(请参阅下面的更多信息)。

您能帮我吗?不幸的是,我发现通过各种搜索找到确定的答案有点挑战。

感谢您的帮助!

测试代码:test.cpp

#include <vector>
#include <iostream>

int main(void) {
    std::vector<int> const v{ 1, 2, 3 };

    std::cout << "Hello world\n";
    std::cout << v[0] << "\n";
    return 0;
}

Linux输出

以下输出来自Linux的Windows子系统,但是在正确的Linux安装上,行为是相同的。

clang -v /mnt/c/Temp/test.cpp -I/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8.0.1
 "/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/bin/clang-8" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.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 /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0 -I /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /mnt/c/Code/v3/Common/cpp/Clang/8 -ferror-limit 19 -fmessage-length 200 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-284194.o -x c++ /mnt/c/Temp/test.cpp -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1
 /usr/local/include
 /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/lib/clang/8.0.0/include
 /usr/include
End of search list.
In file included from /mnt/c/Temp/test.cpp:1:
In file included from /mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/vector:273:
/mnt/c/Code/v3/Common/cpp/Clang/8/Tools/Clang/v8.0.0/Ubuntu/wsl/include/c++/v1/__config:206:12: fatal error: 'features.h' file not found
#  include <features.h>
           ^~~~~~~~~~~~
1 error generated.

Windows输出

clang -v c:\temp\test.cpp
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\bin
clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
 "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -momit-leaf-frame-pointer -v -resource-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\lib\\clang\\8.0.0\\include" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Clang\\8\\Tools\\Clang\\v8.0.0\\Windows\\DefaultEnv\\include\\c++\\v1" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\Catch2\\v2.7.0" -internal-isystem "C:\\Code\\v3\\Common\\cpp\\Common\\Libraries\\C++\\GSL\\v2.0.0\\include" -fdeprecated-macro -fdebug-compilation-dir "C:\\Code\\v3\\Common\\cpp\\Clang\\8" -ferror-limit 19 -fmessage-length 200 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\brownell\\AppData\\Local\\Temp\\test-9329b0.o" -x c++ "c:\\temp\\test.cpp" -faddrsig
clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\lib\clang\8.0.0\include
 C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1
 C:\Code\v3\Common\cpp\Common\Libraries\C++\Catch2\v2.7.0
 C:\Code\v3\Common\cpp\Common\Libraries\C++\GSL\v2.0.0\include
End of search list.
In file included from c:\temp\test.cpp:1:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\vector:274:
In file included from C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\iosfwd:96:
C:\Code\v3\Common\cpp\Clang\8\Tools\Clang\v8.0.0\Windows\DefaultEnv\include\c++\v1\wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

1 个答案:

答案 0 :(得分:2)

对于Linux

在linux上,clag将默认使用gnu对标准库libstdc++的实现。要使用llvm的实现-libc++-首先需要安装它。在ubuntu上,例如:sudo apt install libc++-9-dev libc++abi-9-dev。您可能需要添加苹果存储库。关注these instructions,以获取更多系统和最新版本。然后您需要在编译时显式指定它:-stdlib=libc++。请参阅https://libcxx.llvm.org/docs/UsingLibcxx.html

要链接安装lld(sudo apt install lld-9),然后在使用-fuse-ld=lld进行编译时指定它