2017-02-15 92 views
0

試圖編譯一個簡單的hello世界的例子在Windows上使用鏗鏘聲失敗,我不知道爲什麼,因爲下面的命令顯示包含可能的標題的位置。在窗口(通過瓢安裝)鏗鏘無法找到標題

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> 

作爲命令顯示我從戽斗例如http://scoop.sh/安裝LLVM和tryed通過簡單地調用clang.exe編譯代碼。

我看着clang on Windows - incorrect header file path

,我可以證實,我沒有命名的環境變量或者我的用戶環境變量或從「VS2015或x64原生內運行鐺我的系統環境變量

INCLUDE工具命令提示符「快捷方式似乎工作(基於剛從下載目錄運行」clang hello.c「),但是我如何應用快捷方式對當前正在運行的cmd提示符所做的任何更改?

我沒有使用Cygwin的/ MSYS/MinGW的原因是因爲我相信他們是太重了兩個磁盤空間明智和聰明的複雜

回答

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 

那麼這是如何適用於鏗鏘聲?

那麼你安裝的鏗鏘版本沒有頭文件來編譯一個簡單的hello world例子。這是因爲有許多工具鏈可以用在窗口上,而工具鏈沒有安裝標題的標準位置。所以鏗鏘聲需要他們的一點幫助才能找到標題。

這是vcvarsall.bat文件進來的地方,它爲clang提供了使用安裝的msvc版本頭文件和庫所需的信息。

+0

clang-cl將嘗試幾種技術來發現您的Visual Studio安裝,以便找到運行時庫標頭(並確定-fms-compatibility-version的默認值)。如果您的VS安裝在非標準位置,並且環境缺少常見線索(例如設置了VCINSTALLDIR或PATH中cl.exe的位置),它將無法找到它。使用vcvarsall.bat是確保環境具有足夠信息的絕佳方法。 –

+0

在編寫本文的時候,我並不知道命令clang-cl,因爲我主要在linux/osx上進行了開發,但是我很高興看到這有幫助。 –