分类: Windows平台
2017-12-02 15:16:38
下了官网Pre-built Binaries:( llvm.org/releases/3.5.0/LLVM-3.5.0-win32.exe )03 Sep 2014 3.5.0
(llvm.org) (llvm.org/releases/)
由于刚刚安装了 TDM GCC 4.9.2 tdm64-gcc-4.9.2-3.exe 2014 December 12th(tdm-gcc.tdragon.net)
用mklink将C:\mingw指向tdm64-gcc-4.9.2-3安装目录。
>clang hello.c
hello.c:2:10:fatal error: 'stdio.h' file not found
#include
^
1 error generated.
>
难道又要下载 LLVM + Clang 源代码,修改 llvm-3.5.0.src\tools\clang\lib\Frontend\下的 InitHeaderSearch.cpp,添加tdm64-gcc-4.9.2-3 C/C++ include search path头文件搜索路径,重新编译一次(具体参看旧文Clang+llvm在windows下面怎么配置运行)。看了3.5.0源码,官网Pre-builtBinaries支持到MiniGW 4.8.2。难道每次使用新版 MinGW,都要重复这恼人的编译。
现在,告诉你,只要添加几个环境变量即可。
PATH添加 编译器和LLVM+Clang Command Line Path 命令行运行路径。
至于C/C++ include search path 头文件搜索路径:
使用 MinGW 的,要设置:
C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
使用 Visual C++ 的,要设置:
INCLUDE
当然,如果有附加的链接库
MinGW 设置LIBRARY_PATH
VisualC++ 设置LIB
下面以使用 tdm64-gcc-4.9.2 为例:
Run-Clang.bat
转载请注明引用地址 :http://blog.csdn.net/gocad/article/details/42297829 谢谢
如果使用 tdm32-gcc-4.9.2 则
使用其它版本 MinGW 的,请根据各版本实际路径设置。当然也可以自己编辑成像vcvars32.bat带参数调用。
VisualC++ 用户调用现成的Visual Studio Native Tools Command Prompt,或自己调用 vcvars32.bat 设置 Visual C++ 命令行编译环境。 或Installing MSVC integration
下面是有些需要注意的地方:
关于 –m32/-m64, clang, clang++,clang-cl
默认 ( Target: i686-pc-windows-gnu/i686-pc-windows-msvc,Thread model: posix )
–m32( Target:i386-pc-windows-gnu/i386-pc-windows-msvc,Thread model: posix )
–m64(Target: x86_64-pc-windows-gnu/x86_64-pc-windows-msvc,Thread model: posix )
这与tdm64-gcc-4.9.2默认-m64不同,所以要编译 x64 执行代码,请显式调用-m64。
还有 tdm64-gcc-4.9.2 默认 –m64支持 __int128 is supported on thishost. ( 见c++config.h )
如果同时使用 STL algorithm 与 –m32时,请将 CPLUS_INCLUDE_PATH 中的%MINGW_HOME%\lib\gcc\x86_64-w64-mingw32\%MINGW_VERSION%\include\c++\x86_64-w64-mingw32更改为%MINGW_HOME%\lib\gcc\x86_64-w64-mingw32\%MINGW_VERSION%\include\c++\x86_64-w64-mingw32\32以免编译错误。
如果要用Clang+llvm+MinGW编译 32位执行代码,最好还是使用 MinGW(32),避免因使用 MinGW-w64 设置不恰当,而生成的编译错误。
Clang具体调用模式与使用的命令参数,请用–v命令选项进行追踪
-v Show commands to run and use verbose output
例如:
另外就是,关于 --driver-mode 参数:
clang++等效于 clang--driver-mode=g++
clang-cl等效于 clang--driver-mode=cl
--driver-mode可以覆盖内置或默认值:clang-cl --driver-mode=g++ 等效于 clang++
目前,clang-cl 编译 VC x64/amd64 STL algorithm 时,有时会编译不通过,如:
参考LLVM/Clang On Windows 2013_09(my.oschina.net/GIIoOS/blog/165542)
The support for X86 (both 32-bit and 64-bit) is considered stable onDarwin (Mac OS X), Linux, FreeBSD, and Dragonfly BSD: it has been tested tocorrectly compile many large C, C++, Objective-C, and Objective-C++ codebases.
On x86_64-mingw32, passing i128(by value)is incompatible with the Microsoft x64 calling convention. You might need totweak WinX86_64ABIInfo::classify() in lib/CodeGen/TargetInfo.cpp.
For the X86 target, clang supports the -m16 command line argument which enables16-bit code output. This is broadly similar to using asm(".code16gcc") with the GNU toolchain.The generated code and the ABI remains 32-bit but the assembler emitsinstructions appropriate for a CPU running in 16-bit mode, with address-sizeand operand-size prefixes to enable 32-bit addressing and operations.
Clang works on some mingw32 distributions. Clang assumes directories asbelow;
On MSYS, a few tests might fail.
For 32-bit (i686-w64-mingw32), and 64-bit (x86_64-w64-mingw32), Clangassumes as below;
This directory layout is standard for any toolchain you will find on theofficial .
Clang expects the GCC executable “gcc.exe” compiled for i686-w64-mingw32 (or x86_64-w64-mingw32) to be present on PATH.
on x86_64-w64-mingw32.
clang-cl is an alternative command-line interface to Clang driver,designed for compatibility with the Visual C++ compiler, cl.exe.
To enable clang-cl to find system headers, libraries, and the linker whenrun from the command-line, it should be executed inside a Visual Studio NativeTools Command Prompt or a regular Command Prompt where the environment has beenset up using e.g. .
clang-cl can also be used from inside Visual Studio by using an LLVMPlatform Toolset.
转载请注明引用地址 :http://blog.csdn.net/gocad/article/details/42297829 谢谢