如何在Windows上使用mingw-w64标题使用clang [英] How to use clang with mingw-w64 headers on windows

查看:1429
本文介绍了如何在Windows上使用mingw-w64标题使用clang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 http://llvm.org /releases/3.9.0/LLVM-3.9.0-win32.exe

  clang version 3.9.0(分支/ release_39)
目标:i686-pc-windows-msvc
线程模型:posix
InstalledDir:C:\程序文件\LLVM\bin

和gcc 6.2.0(Mingw-w64)

  gcc(i686-posix-dwarf-rev1,由MinGW-W64项目构建)6.2.0 
版权所有(C)2016 Free Software Foundation,Inc.
这是自由软件;请参阅复制条件的来源。没有任何b $ b保修;甚至不适用于适销性或针对特定用途的适用性。

我的电脑上没有安装MSVC,也没有安装Windows SDK。我需要clang的一些特殊功能,我想用gcc替换它,更确切地说用g ++来替换它,因为我使用了C ++。

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


致命错误:找不到字符串文件

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



这是否也意味着我的铛安装取决于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编译的。 / p>

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


我认为它解释了一切。这是否意味着我需要mingw构建才能使用mingw?

解决方案

正确的做法是,

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

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

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

锵将确定您路径中标题和库的位置。确保你的路径中只有Mingw的版本。



默认情况下,当前版本的Clang(5.0.0截至目前)将目标 x86_64-pc-windows-msvc



举例来说...

  Microsoft Windows [版本10.0.16299.19] 
(c)2017 Microsoft Corporation。版权所有。

C:\Users\burito>副本con hello.c
#include

int main(int argc,char * argv [])
{
printf(Hello World!\\\
);
返回0;
}
^ Z
复制1个文件。

C:\Users\burito> clang hello.c -ohello.exe --verbose
铿锵声5.0.0版(tags / RELEASE_500 / final)
目标: x86_64-pc-windows-msvc
线程模型:posix
InstalledDir:C:\程序文件\LLVM\bin
clang.exe:警告:无法找到Visual Studio安装;尝试从开发人员命令提示符处运行Clang [-Wmsvc-not-found]
C:\\ Program Files \\LLVM\\\\\\\\\\\\\'-cc1 - 三重x86_64-pc-windows-msvc18.0.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free-disable -llvm-verifier -discard -value -name -main-file-name hello.c - mrelocation-模型PIC -pic级2 -mthread模型POSIX -fmath-错误号-masm-冗长-mconstructor-别名-munwind桌-target-CPU的x86-64 -momit叶帧指针-v -dwarf- column-info -debugger-tuning = gdb -resource-dirC:\\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 S tudio 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 -dirC:\\ Users \\\\\\\\'\\\\\\\\\\\\\\' -template-parsing -fobjc-runtime = gcc -fdiagnostics -show-option -fcolor-diagnostics -oC:\\ Users \\\\\\\\\\\\\\\\\\\ \\hello-5c526d.o-xc hello.c
clang -cc1版本5.0.0基于LLVM 5.0.0默认目标x86_64-pc-windows-msvc
忽略不存在的目录C :/ Program Files / Microsoft Visual Studio 10.0 / VC / include
忽略不存在的目录C:/ Program Files / Microsoft Visual Studio 9.0 / VC / include
忽略不存在的目录C:/ Program Files / Microsoft Visual Studio 9.0 / VC / PlatformSDK /包含
igno ring不存在的目录C:/ Program Files / Microsoft Visual Studio 8 / VC / include
忽略不存在的目录C:/ Program Files / Microsoft Visual Studio 8 / VC / PlatformSDK / Include
#include ...搜索从这里开始:
#include< ...>搜索从这里开始:
C:\程序文件\LLVM\lib\clang\5.0.0\include
搜索列表结束。
hello.c:1:10:致命错误:找不到'stdio.h'文件
#include< stdio.h>
^ ~~~~~~~~
1错误产生。

C:\Users\burito> clang hello.c -ohello.exe --verbose -target x86_64-pc-windows-gnu
铿锵声5.0.0版(tags / RELEASE_500 / final)
目标:x86_64-pc-windows-gnu
线程模型:posix
InstalledDir:C:\程序文件\LLVM\bin
C:\\ \\\程序文件\\\LLVM \\\\\\\\\\\\\\`````-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-dirC:\\Program Files\\LLVM\\lib \\clang\\5.0.0-internal-isystemC:\\Program Files\\\LLVM\\lib\\clang\\5.0.0\ \include-internal-isystemC:\\程序文件\\mingw-w64\\x86_64-7.2.0-POSIX的SEH-rt_v5-rev0\\mingw64\\x86_64-W64-的mingw32 / SYS-根/ MinGW的/包括 -internal- ISYSTEMC:\\Program Files\\mingw-w64\\x86_64-7.2.0-POSIX的SEH-rt_v5-rev0\\mingw64\\x86_64-W64-mingw32\ \include-internal-isystemC:\\Program Files\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\包括 -fdebug编译-DIR C:\\Users\\burito -ferror限值19 -fmessage长度120 -fno使用-CXA-atexit对-fobjc-运行时间= GCC -fdiagnostics放映-option -fcolor-diagnostics -oC:\\\\\ Users \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\''-xc hello。 c
clang -cc1版本5.0.0基于LLVM 5.0.0默认目标x86_64-pc-windows-msvc
忽略不存在的目录C:\程序文件\明确-w64\x86_64- 7.2.0-POSIX-SEH-rt_v5-rev0\\ \\\\\\\\\\\\\\\\\\\'\\\\\\\\\'搜索从这里开始:
C:\程序文件\LLVM\lib\clang\5.0.0\include
C:\程序文件\明确-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
搜索列表结束。
C:\\ Program Files \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ ld.exe-m i386pep -Bdynamic -o hello.exeC:\\ Program Files \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \mingw64\\\x86_64-w64-mingw32\\\lib\\crt2.oC:\\Program Files\\\\\\\\\\\\\\\\\\\\\\\ -posix-seh-rt_v5-rev0 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ :\\ Program Files \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ x86_64-w64-mingw32 \\\\\\\7.2.0-LC:\\Program Files\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\\lib-LC:\\ Program Files \\\\\\\\\\\\\\\\\\\\\\ -posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32 / sys-root / mingw / libC:\\ Users \\\\\\\\\\\\\\\ \\\Local\\Temp\\hello-d88ba4.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex - lmsvcrtC:\\Program Files\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'

C:\Users\burito>


I have clang 3.9 from http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe

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 (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. I need some particular feature of clang and I wanted to replace it with gcc and more specifically with g++ because I use C++.

When I try to compile simple file I get:

fatal error: 'string' file not found

Does it mean my current clang installation doesn't support mingw on windows? Basically all I want is to use headers and libs from my mingw-w64 installation. 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?

EDIT: From the comment on this page: 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.

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.

I think it explains everything. Does it mean I need mingw build to get it working with mingw?

解决方案

The correct thing to do, is this...

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

Or if you want 64bit output...

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

Clang will determine the location of the headers and libraries from your path. Make sure that you only have the version of Mingw in your path that you are targetting.

By default, the current release of Clang (5.0.0 as of now) will target 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>

这篇关于如何在Windows上使用mingw-w64标题使用clang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆