简体   繁体   English

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

[英]How to use clang with mingw-w64 headers on windows

I have clang 3.9 from http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe 我有来自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

And gcc 6.2.0 (Mingw-w64) 和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.

I don't have MSVC installed on my PC and no Windows SDK. 我的PC上没有安装MSVC,也没有安装Windows SDK。 I need some particular feature of clang and I wanted to replace it with gcc and more specifically with g++ because I use C++. 我需要clang的一些特殊功能,我想用gcc替换它,更具体地说用g ++替换它因为我使用C ++。

When I try to compile simple file I get: 当我尝试编译简单文件时,我得到:

fatal error: 'string' file not found 致命错误:找不到'string'文件

Does it mean my current clang installation doesn't support mingw on windows? 这是否意味着我目前的clang安装不支持windows上的mingw? Basically all I want is to use headers and libs from my mingw-w64 installation. 基本上我只想使用mingw-w64安装中的头文件和库。 I was looking for solution and didn't find anything. 我一直在寻找解决方案而没有找到任何东西。 I don't know what should I do. 我不知道该怎么办。

Does it also mean my clang installation depends on MSVC that I don't have? 这是否也意味着我的clang安装取决于我没有的MSVC?

EDIT: From the comment on this page: http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/ 编辑:从本页面的评论: http//blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/

This doesn't work anymore with the latest binaries (3.7.1, 3.8, 3.9) from LLVM, because these were compiled with Visual Studio and for Visual Studio. 这不再适用于LLVM的最新二进制文件(3.7.1,3.8,3.9),因为它们是使用Visual Studio和Visual Studio编译的。

You can install the full Visual Studio 2015 (takes about 8GB) or install "Microsoft Visual C++ Build Tools 2015 Update 3" which contains only the command line tools from VS plus the standard C++ header files that Clang needs. 您可以安装完整的Visual Studio 2015(大约8GB)或安装“Microsoft Visual C ++ Build Tools 2015 Update 3”,其中仅包含VS的命令行工具以及Clang所需的标准C ++头文件。

I think it explains everything. 我认为它解释了一切。 Does it mean I need mingw build to get it working with mingw? 这是否意味着我需要mingw构建才能让它与mingw一起工作?

The correct thing to do, is this... 正确的做法是,这......

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

Or if you want 64bit output... 或者如果你想要64位输出......

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

Clang will determine the location of the headers and libraries from your path. Clang将根据您的路径确定标头和库的位置。 Make sure that you only have the version of Mingw in your path that you are targetting. 确保您在目标路径中只有Mingw版本。

By default, the current release of Clang (5.0.0 as of now) will target x86_64-pc-windows-msvc 默认情况下,Clang的当前版本(截至目前为5.​​0.0)将针对x86_64-pc-windows-msvc

By way of example... 举例来说......

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>

After installing older version built with MinGW that is 3.7.0 RC3 it worked. 安装使用MinGW构建的旧版本3.7.0 RC3后,它工作正常。

You can notice the difference in version i686-pc-windows- gnu vs i686-pc-windows- msvc . 您可以注意到版本i686-pc-windows- gnu与i686-pc-windows- msvc的区别。

I think clang 3.9 would work too if they didn't break something in their source code and if you'd build it yourself. 我认为如果他们没有在源代码中破坏某些内容并且你自己构建它,那么clang 3.9也会起作用。 Would be nice to have newest 3.9 working with MinGW too. 最新的3.9也可以与MinGW合作。 I'm too lazy though to try to build it myself. 虽然我自己也试图建立它,但我太懒了。

EDIT: There are some packages for mingw too https://github.com/Alexpux/MINGW-packages that you can install using MSYS2 that seem to provide support for clang. 编辑: mingw也有一些软件包https://github.com/Alexpux/MINGW-packages你可以使用MSYS2安装,似乎提供了对clang的支持。 There are some commits related to 3.8 and 3.9. 有一些提交与3.8和3.9相关。

Hope this will help someone that has similar problems. 希望这能帮助有类似问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM