我本意是想在windows下學習下C++11,而結果是我的Visual Studio 2012不完全支持,而我又懶得去安裝2013/2015,太大了。公司運維也不允許我去下載- -,然后就想能不能在windows環境下搞個gcc玩,然后我又知乎了一把,大意的意見是clang把gcc甩了好遠,所以我就決定安裝clang環境來學習一下,過程中還是遇了幾個坑…
-----------------------------------------------------------------------------------------------
下載最新的clang版本,地址:http://www.llvm.org/releases/download.html#3.7.0
然后編寫測試用的c代碼,保存為demo1.c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello World!");
return 0;
}
使用Win + R,切換到demo1.c的目錄下,然后執行clang --verbose demo1.c會遇到錯誤
找不到stdio.h文件,之后我在網上搜索了好久,比如這一篇文章
http://zanedp.blogspot.com/2014/01/clang-cant-find-stdioh-etc.html
我按照文章提示的步驟進行安裝,最后發現遇到這樣的錯誤:
ld.exe: unrecognised emulation mode: i386pepSupported emulations: i386pe
這個問題很頭疼,google出來的結果很多,卻幾乎沒什么頭緒,最后我在一個郵件列表中找到了答案
http://comments.gmane.org/gmane.comp.lib.boost.devel/262947
缺少stdio.h,下載mingw沒有問題,問題是我使用的不是64位的!
然后我搜索關鍵字“mingw 64”,總算讓我找到了答案,下載地址:http://mingw-w64.org/doku.php/download
注意CPU架構選擇x86_64,原因就是clang也使用的是該架構編譯的
安裝成功后,查看gcc的相關信息(需要把gcc安裝目錄的bin加入到環境變量)
如果還編譯不通過(我遇到了),關閉當前的dos窗口,然后重新來一遍就可以了
main.cpp的源碼:
#include <iostream>
#include <vector>
int main()
{
std::vector<int> vect {1, 2, 3, 4, 5};
for(auto& el : vect)
std::cout << " - " << el << std::endl;
return 0;
}