windows上使用clang编译程序

C 专栏收录该内容
12 篇文章 0 订阅

windows上使用clang编译程序

环境:windows10,64位

  1. 下载并安装llvm,安装包里除了llvm,也有clang:

http://releases.llvm.org/5.0.0/LLVM-5.0.0-win64.exe

  1. 下载并安装mingw:

https://sourceforge.net/projects/mingw-w64/

安装时选择CPU架构为 x86_64

把安装路径添加到path中:

C:\Program Files\mingw-w64\x86_64-7.1.0-posix-seh-rt_v5-rev2\mingw64\bin

  1. 打开命令行窗口,开始编译程序:
    clang --target=x86_64-pc-mingw64 hello.c -o hello.exe

为什么要加target?

clang hello.c -o hello.exe 会报错,

clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
.\int_hash.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
        ^~~~~~~~~
1 error generated.

gcc - How to use clang with mingw-w64 headers on windows - Stack Overflow
Cross-compilation using Clang — Clang 13 documentation (llvm.org)
查看Cross-compilation,交叉编译的文档可以看到,如下。

Cross compilation issues
In GCC world, every host/target combination has its own set of binaries, headers, libraries, etc. So, it’s usually simple to download a package with all files in, unzip to a directory and point the build system to that compiler, that will know about its location and find all it needs to when compiling your code.

On the other hand, Clang/LLVM is natively a cross-compiler, meaning that one set of programs can compile to all targets by setting the -target option. That makes it a lot easier for programmers wishing to compile to different platforms and architectures, and for compiler developers that only have to maintain one build system, and for OS distributions, that need only one set of main packages.

But, as is true to any cross-compiler, and given the complexity of different architectures, OS’s and options, it’s not always easy finding the headers, libraries or binutils to generate target specific code. So you’ll need special options to help Clang understand what target you’re compiling to, where your tools are, etc.

Another problem is that compilers come with standard libraries only (like compiler-rt, libcxx, libgcc, libm, etc), so you’ll have to find and make available to the build system, every other library required to build your software, that is specific to your target. It’s not enough to have your host’s libraries installed.

Finally, not all toolchains are the same, and consequently, not every Clang option will work magically. Some options, like --sysroot (which effectively changes the logical root for headers and libraries), assume all your binaries and libraries are in the same directory, which may not true when your cross-compiler was installed by the distribution’s package management. So, for each specific case, you may use more than one option, and in most cases, you’ll end up setting include paths (-I) and library paths (-L) manually.

To sum up, different toolchains can:

  • be host/target specific or more flexible
  • be in a single directory, or spread out across your system
  • have different sets of libraries and headers by default
  • need special options, which your build system won’t be able to figure out by itself

在GCC世界中,每个主机/目标组合都有自己的一组二进制文件、头文件、库等。因此,下载一个包含所有文件的包,解压到一个目录,并将构建系统指向该编译器,该编译器将知道其位置,并在编译代码时找到所有需要的文件。
另一方面,Clang/LLVM本质上是一个交叉编译器,这意味着一组程序可以通过设置-target选项编译到所有目标。这使得希望编译到不同平台和体系结构的程序员、只需要维护一个构建系统的编译器开发人员以及只需要一组主软件包的操作系统发行版更容易。

但是,与任何交叉编译器一样,考虑到不同体系结构、操作系统和选项的复杂性,查找头、库或binutil以生成特定于目标的代码并不总是那么容易。因此,您需要特殊的选项来帮助Clang了解编译的目标、工具的位置等。

另一个问题是编译器只附带标准库(如编译器rt、libcxx、libgcc、libm等),因此您必须找到构建软件所需的每个其他库,这些库是特定于您的目标的,并提供给构建系统。仅安装主机的库是不够的。

最后,并非所有的工具链都是相同的,因此,并非每个叮当声选项都能神奇地工作。有些选项,如–sysroot(它可以有效地更改头和库的逻辑根),假定所有二进制文件和库都在同一个目录中,这在发行版的包管理安装交叉编译器时可能不正确。因此,对于每个特定情况,您可以使用多个选项,在大多数情况下,您将手动设置include path(-I)和library path(-L)。

总之,不同的工具链可以:

  • 特定于主机/目标或更灵活
  • 位于单个目录中,或分散在整个系统中
  • 默认情况下,具有不同的库和标题集
  • 需要特殊的选项,这是构建系统无法自行解决的

上面文档的意思是,GCC是默认指定了自己的依赖库、头文件等,是完整的一套,不需要额外的东西就可以运行;而clang并不一定具备,因为他是交叉编译器(例如,在windows下编译出mingw是我目标),所以需要额外的选项来指定。

下面来尝试如何在windows下不用target选项来编译源代码。

如下,gcc的target是Target: x86_64-w64-mingw32

PS C:\Users\BruceLee\Desktop\clang> gcc -v
Using built-in specs.
COLLECT_GCC=C:\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

clang的target是Target: x86_64-pc-windows-msvc

PS C:\Users\BruceLee\Desktop\clang> clang -v
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

因此在clang默认编译的过程中,会寻找msvc的相关库和头文件

PS C:\Users\BruceLee\Desktop\clang> clang .\main.c -o main --verbose
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 10.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/include" -internal-isystem "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include" -fdebug-compilation-dir "C:\\Users\\BruceLee\\Desktop\\clang" 
-ferror-limit 19 -fmessage-length=201 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -fdelayed-template-parsing -fcolor-diagnostics -faddrsig -o "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-c8ed50.o" -x c ".\\main.c"
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\12.0.0\include
End of search list.
.\main.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

会发现在*/VC/include里面寻找头文件。
如果把环境变量INCLUDE设置成各个库的include,C:\mingw64\x86_64-w64-mingw32\include;C:\mingw64\include;C:\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include;

PS C:\Users\BruceLee\Desktop\clang> clang .\main.c -o main --verbose
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
clang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\mingw64\\x86_64-w64-mingw32\\include" 
-internal-isystem "C:\\mingw64\\include" -internal-isystem "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include" -fdebug-compilation-dir "C:\\Users\\BruceLee\\Desktop\\clang" -ferror-limit 19 -fmessage-length=201 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -fdelayed-template-parsing -fcolor-diagnostics -faddrsig -o "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-4b0d59.o" -x c ".\\main.c"
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\12.0.0\include
 C:\mingw64\x86_64-w64-mingw32\include
 C:\mingw64\include
 C:\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include
End of search list.
 "link.exe" -out:main -defaultlib:libcmt -defaultlib:oldnames "-libpath:C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\lib\\windows" -nologo "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-4b0d59.o"
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)

会发现多了,说明INCLUDE生效了(要重新启动命令行,保证环境变量生效),头文件的问题解决了。

 C:\mingw64\x86_64-w64-mingw32\include
 C:\mingw64\include
 C:\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include

但是仍然报错,看样子是链接的问题。先试下仅编译出.o来,是成功的,说明确实是链接有问题。

PS C:\Users\BruceLee\Desktop\clang> clang -c .\main.c -o main.o -v
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 (in-process)
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\mingw64\\x86_64-w64-mingw32\\include" 
-internal-isystem "C:\\mingw64\\include" -internal-isystem "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\include" -fdebug-compilation-dir "C:\\Users\\BruceLee\\Desktop\\clang" -ferror-limit 19 -fmessage-length=201 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -fdelayed-template-parsing -fcolor-diagnostics -faddrsig -o main.o -x c ".\\main.c"
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\12.0.0\include
 C:\mingw64\x86_64-w64-mingw32\include
 C:\mingw64\include
 C:\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\include
End of search list.

用gcc进行链接是OK的,说明前面编译的环节上没问题的。

PS C:\Users\BruceLee\Desktop\clang> gcc .\main.o -o main    
PS C:\Users\BruceLee\Desktop\clang> .\main.c
PS C:\Users\BruceLee\Desktop\clang> .\main  
hello world
PS C:\Users\BruceLee\Desktop\clang> 

下面修改下target=x86_64-w64-mingw32,试一下。

S C:\Users\BruceLee\Desktop\clang> clang -target x86_64-w64-mingw32 .\main.c -o main.o -v
clang version 12.0.0
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -mms-bitfields -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\mingw64\\include" -fdebug-compilation-dir "C:\\Users\\BruceLee\\Desktop\\clang" -ferror-limit 19 -fmessage-length=201 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -exception-model=seh -fcolor-diagnostics -faddrsig -o "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-d65ec3.o" -x c ".\\main.c"
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\mingw64\x86_64-w64-mingw32/sys-root/mingw/include" 
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\12.0.0\include
 C:\mingw64\x86_64-w64-mingw32\include
 C:\mingw64\include
End of search list.
 "C:\\mingw64\\bin\\ld.exe" -m i386pep -Bdynamic -o main.o "C:\\mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\crtbegin.o" "-LC:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0" "-LC:\\mingw64\\x86_64-w64-mingw32\\lib" "-LC:\\mingw64\\lib" "-LC:\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" "-LC:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\lib\\windows" "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-d65ec3.o" -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 "C:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\8.1.0\\crtend.o"

"C:\\mingw64\\bin\\ld.exe"前面的部分是一样的;此外,这块链接用的是ld.exe,前面用的"link.exe"
这说明最初前面没有添加target的命令默认去搜索msvc的链接器,但是没有找到,所以才报的错。
另外一点,ignoring nonexistent directory "C:\mingw64\x86_64-w64-mingw32/sys-root/mingw/include"这个warning也和前面的不一样。

总结:切了target后,clang会去搜索相匹配的库、头文件以及其他编译组件,这和文档里面说的是一致的。

如果想用link.exe 进行链接,估计要装msvc相关的组件了。
为了验证这个问题,安装了visual stadio 2022,

PS C:\Users\BruceLee\Desktop\clang> clang .\main.c -o main -v
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.30.30423 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu 
generic -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.30.30423\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.30.30423\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\winrt" -fdebug-compilation-dir "C:\\Users\\BruceLee\\Desktop\\clang" -ferror-limit 19 -fmessage-length=201 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.30.30423 -fdelayed-template-parsing -fcolor-diagnostics -faddrsig -o 
"C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-d659bd.o" -x c ".\\main.c"
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc  
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\12.0.0\include
 C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30423\include
 C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30423\atlmfc\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt
End of search list.
 "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.30.30423\\bin\\Hostx64\\x64\\link.exe" -out:main -defaultlib:libcmt -defaultlib:oldnames "-libpath:C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\lib\\windows" -nologo "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-d659bd.o"
LINK : fatal error LNK1104: 无法打开文件“libcmt.lib”
clang: error: linker command failed with exit code 1104 (use -v to see invocation)

link.exe已经找到了。但因为库打不开, 还是失败了。
定位到libcmt.lib的位置,修改lib的环境变量;后面有缺lib的,都加进去。(命令行关闭后,再打开,才能生效)
修改环境变量
最后,终于成功了。。

PS C:\Users\BruceLee\Desktop\clang> clang .\main.c -o main -v
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.30.30423 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu 
generic -v -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.30.30423\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.30.30423\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\winrt" -fdebug-compilation-dir "C:\\Users\\BruceLee\\Desktop\\clang" -ferror-limit 19 -fmessage-length=201 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.30.30423 -fdelayed-template-parsing -fcolor-diagnostics -faddrsig -o 
"C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-7b3d90.o" -x c ".\\main.c"
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\12.0.0\include
 C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30423\include
 C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.30.30423\atlmfc\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt
End of search list.
 "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.30.30423\\bin\\Hostx64\\x64\\link.exe" -out:main -defaultlib:libcmt -defaultlib:oldnames "-libpath:C:\\Program Files\\LLVM\\lib\\clang\\12.0.0\\lib\\windows" -nologo "C:\\Users\\BruceLee\\AppData\\Local\\Temp\\main-7b3d90.o"
PS C:\Users\BruceLee\Desktop\clang> .\main                   
hello world

简单的输出:

PS C:\Users\BruceLee\Desktop\clang> clang .\main.c -o main   
PS C:\Users\BruceLee\Desktop\clang> .\main
hello world

Yes,I did it.

  • 1
    点赞
  • 1
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页

打赏作者

freelander0418

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值