【问题标题】:clang on windows (installed via scoop) is unable to find headerswindows上的clang(通过scoop安装)无法找到标题
【发布时间】:2017-02-15 17:42:43
【问题描述】:

尝试在 windows 上使用 clang 编译一个简单的 hello world 示例失败,我不知道为什么,因为下面的命令显示包含可能标题的位置。

C:\Users\peter\Downloads>clang-cl -v hello.c
clang version 3.9.1 (branches/release_39)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\peter\scoop\apps\llvm\current\bin
"C:\\Users\\peter\\scoop\\apps\\llvm\\current\\bin\\clang-cl.exe" -cc1 -triple x86_64-pc-windows-msvc19.0.24215 -emit-obj -mrelax-all mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fms-volatile -fdiagnostics-format msvc -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -resource-dir "C:\\Users\\peter\\scoop\\apps\\llvm\\current\\bin\\..\\lib\\clang\\3.9.1" -internal-isystem "C:\\Users\\peter\\scoop\\apps\\llvm\\current\\bin\\..\\lib\\clang\\3.9.1\\include" -internal-isystem "F:\\visualstudio2015\\VC\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\" -internal-isystem "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\" -internal-isystem "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\" -fdebug-compilation-dir "C:\\Users\\peter\\Downloads" -ferror-limit 19 -fmessage-length 120 -fms-extensions -fms-compatibility -fms-compatibility-version=19.0.24215 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\peter\\AppData\\Local\\Temp\\hello-8512ad.obj" -x c hello.c
clang -cc1 version 3.9.1 based upon LLVM 3.9.1 default target x86_64-pc-windows-msvc
ignoring duplicate directory "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A"
ignoring duplicate directory "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A"
#include "..." search starts here:
#include <...> search starts here:
C:\Users\peter\scoop\apps\llvm\current\bin\..\lib\clang\3.9.1\include
F:\visualstudio2015\VC\include
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A
End of search list.
hello.c(3,10):  fatal error: 'stdio.h' file not found
#include <stdio.h>
     ^
1 error generated.

C:\Users\peter\Downloads>

正如命令所示,我从 scoop 安装了 llvm,例如 http://scoop.sh/,并尝试通过简单地调用 clang.exe 来编译代码。

我在看clang on Windows - incorrect header file path

我可以确认我的用户环境变量或系统环境变量中都没有名为 INCLUDE 的环境变量

从“VS2015 x64 Native Tools Command Prompt”快捷方式中运行 clang 似乎有效(基于从下载目录中运行“clang hello.c”)但是我如何应用该快捷方式对当前运行的任何更改cmd提示符?

我不使用 cygwin/msys/mingw 的原因是因为我认为它们在磁盘空间和复杂性方面都太重了

【问题讨论】:

    标签: windows clang


    【解决方案1】:

    很好地回答那些快捷方式调用的问题

    "<location of visual studio install path>\vcvarsall.bat" <platform you want to build for>
    

    或显示整个命令

    %comspec% /k ""F:\visualstudio2015\VC\vcvarsall.bat"" amd64
    

    因此,如果您想将快捷方式的内容应用于当前正在运行的命令环境,请在命令提示符下执行此操作。

    "F:\visualstudio2015\VC\vcvarsall.bat" amd64
    

    那么这如何适用于 clang?

    您安装的 clang 版本没有用于在 Windows 上编译简单的 hello world 示例的标头。这是因为有许多工具链可以在 Windows 上使用,而且这些工具链没有安装头文件的标准位置。所以 clang 需要他们的一点帮助才能找到标题。

    这是 vcvarsall.bat 文件的来源。它为 clang 提供所需的信息以使用已安装的 msvc 版本头文件和库。

    【讨论】:

    • clang-cl 将尝试多种技术来发现您的 Visual Studio 安装,以便定位运行时库标头(并确定 -fms-compatibility-version 的默认值)。如果您的 VS 安装在非标准位置并且环境缺少通常的线索(例如设置了 VCINSTALLDIR 或 PATH 中 cl.exe 的位置),它将无法找到它。使用 vcvarsall.bat 是确保环境有足够信息的绝佳方式。
    • 在写这篇文章的时候,我还不知道命令 clang-cl,因为我主要在 linux/osx 上进行开发,但我很高兴这对我有帮助。
    猜你喜欢
    • 2022-06-20
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    相关资源
    最近更新 更多