如何在Windows上使用带有mingw-w64标头的clang

康拉德

我有http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe的clang 3.9

clang version 3.9.0 (branches/release_39)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

和gcc 6.2.0(Mingw-w64)

gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我的PC上没有安装MSVC,也没有Windows SDK。我需要clang的某些特殊功能,我想用gcc代替它,更具体地说是用g ++代替,因为我使用C ++。

当我尝试编译简单文件时,我得到:

严重错误:找不到“字符串”文件

这是否意味着我当前的clang安装在Windows上不支持mingw?基本上,我想要的只是使用mingw-w64安装中的标头和库。我一直在寻找解决方案,但没有找到任何东西。我不知道该怎么办。

这是否还意味着我的clang安装依赖于我没有的MSVC?

编辑:从此页上的评论:http : //blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/

这不适用于LLVM的最新二进制文件(3.7.1、3.8、3.9),因为它们是使用Visual Studio和Visual Studio编译的。

您可以安装完整的Visual Studio 2015(约8GB)或安装“ Microsoft Visual C ++ Build Tools 2015 Update 3”,其中仅包含VS中的命令行工具以及Clang所需的标准C ++头文件。

我认为这说明了一切。这是否意味着我需要mingw构建才能使其与mingw一起使用?

burito

正确的做法是...

clang -target i686-pc-windows-gnu test.c -otest.exe

或者如果您想要64位输出...

clang -target x86_64-pc-windows-gnu test.c -otest.exe

Clang将根据您的路径确定标头和库的位置。确保目标路径中只有Mingw版本。

默认情况下,当前版本的Clang(截至目前为5.​​0.0)将定位 x86_64-pc-windows-msvc

举例来说...

Microsoft Windows [Version 10.0.16299.19]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\burito>copy con hello.c
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello World!\n");
    return 0;
}
^Z
        1 file(s) copied.

C:\Users\burito>clang hello.c -ohello.exe --verbose
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
clang.exe: 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-    msvc18.0.0 -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 -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\5.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\\burito" -ferror-limit 19 -fmessage-length 120 -fms-extensions -fms-compatibility -fms-compatibility-version=18 -fno-threadsafe-statics -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\burito\\AppData\\Local\\Temp\\hello-5c526d.o" -x c hello.c
clang -cc1 version 5.0.0 based upon LLVM 5.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\5.0.0\include
End of search list.
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

C:\Users\burito>clang hello.c -ohello.exe --verbose -target x86_64-pc-windows-gnu
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-pc-windows-gnu
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
 "C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0\\include" -internal-isystem "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\include" -fdebug-compilation-dir "C:\\Users\\burito" -ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\burito\\AppData\\Local\\Temp\\hello-d88ba4.o" -x c hello.c
clang -cc1 version 5.0.0 based upon LLVM 5.0.0 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\x86_64-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM\lib\clang\5.0.0\include
 C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\x86_64-w64-mingw32\include
 C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\include
End of search list.
 "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\bin\\ld.exe" -m i386pep -Bdynamic -o hello.exe "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0\\crtbegin.o" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\lib" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" "C:\\Users\\burito\\AppData\\Local\\Temp\\hello-d88ba4.o" -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0\\crtend.o"

C:\Users\burito>hello
Hello World!

C:\Users\burito>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在MinGW w64 4.8中使用Clang 3.6

CMake:如何在 Windows 上使用 clang 和 lld 使用 MinGW-w64 运行时编译 C

Mingw64-w64属性(格式)和<cinttypes>标头

如何在 Windows 上使用带有 C++ 的 x64 程序集?

如何在Windows(使用Qt Creator)上构建64位MinGW Qt应用程序

搜索-lglut32 new时Mingw w64的链接器跳过不兼容

如何在 Windows 10 上安装 MinGW 64

clang / clang ++在Windows中找不到C / C ++标头?

如何使用clang从源文件中提取标头?

如何在带有Cygwin64 Terminal的Windows 10上通过rvm安装Ruby?

Clang不再使用<functional>标头编译程序

如何用clang和mingw-w64进行编译?

如何在带有预编译标头的项目中使用google protobuf

如何在带有参数和标头的Android Volley库中使用POST请求?

如何在CMake和clang-tidy中使用SYSTEM标头?

如何在Windows 10上为代码块17.02指定MinGW64?

如何在 Windows 10 上为代码块 17.02 指定 MinGW64?

如何在 Windows 上的 git bash (MINGW64) 中停止滚动输出?

如何使用带有 Rails 的 minitest 访问请求的标头?

如何使用带有标头和.so文件的库?

如何在Clang中的标准库中提取标头的搜索路径?

Logstash配置:带有Base 64编码标头的http输出

EPEL的Amazon Linux上的Clang找不到C ++标头或库

编译clang的<noreturn.h>和Windows标头时的declspec错误

如何在Windows上使用和配置clang-tidy?

在带有Bazel的Android Lib上包含JNI标头

不能在带有CORS的AWS API Gateway上使用自定义请求标头

如何在Spring Boot中读取带有标头和正文的JSON

如何在Swagger UI中发送带有请求的自定义标头?