简体   繁体   English

如何用clang和mingw-w64编译?

[英]How to compile with clang and mingw-w64?

I'm trying to use clang10 with mingw-w64's libstdc++, since the MSVC headers don't support clang 10. I don't mind not having the new parts of the standard library, I just want to use the new language features.我正在尝试将 clang10 与 mingw-w64 的 libstdc++ 一起使用,因为 MSVC 标头不支持 clang 10。我不介意没有标准库的新部分,我只想使用新的语言功能。

I have mingw-w64 version 8.1.0 for x86_64 with POSIX threads and SEH exceptions installed and I run clang with a command:我有用于 x86_64 的 mingw-w64 版本 8.1.0,安装了 POSIX 线程和 SEH 异常,我使用命令运行 clang:

clang++ -target x86_64-pc-windows-gnu -std=c++20 ...

Everything works OK.一切正常。 All the language features that should be implemented in clang 10 work, but when I throw any exception, this happens when I run the program (the program compiles OK):所有应该在 clang 10 中实现的语言功能都有效,但是当我抛出任何异常时,当我运行程序时会发生这种情况(程序编译正常):

Mingw-w64 runtime failure:
  Unknown pseudo relocation protocol version 65536.

I tried installing mingw with SJLJ exceptions and use the -fsjlj-exceptions flag in clang, but the program doesn't even compile:我尝试安装带有 SJLJ 异常的 mingw 并在 clang 中使用-fsjlj-exceptions标志,但该程序甚至无法编译:

C:\Users\egst\AppData\Local\Temp\test-f4a4de.o:test.cpp:(.text+0x82): undefined reference to `__gxx_personality_sj0'
C:\Users\egst\AppData\Local\Temp\test-f4a4de.o:test.cpp:(.text+0xd9): undefined reference to `_Unwind_SjLj_Register'
C:\Users\egst\AppData\Local\Temp\test-f4a4de.o:test.cpp:(.text+0x177): undefined reference to `_Unwind_SjLj_Resume'

clang++ --version shows Target: x86_64-pc-windows-msvc . clang++ --version显示Target: x86_64-pc-windows-msvc Maybe there's a version for x86_64-pc-windows-gnu that I should use instead?也许我应该使用x86_64-pc-windows-gnu的版本? Is there any way to make this work at this moment, or should I wait for support from MSVC?目前有什么方法可以使它工作,还是我应该等待 MSVC 的支持? Is there maybe any alternative besides MSVC and MinGW?除了 MSVC 和 MinGW 之外,还有其他选择吗?

Based on @HolyBlackCat 's sugestion, I tried this with MSYS2 and it works perfectly.基于@HolyBlackCat 的建议,我使用 MSYS2 进行了尝试,它运行良好。 I simply installed MSYS2, then from the MSYS bash I installed this package. It installs everything in in ...\msys2\mingw64 .我只是安装了 MSYS2,然后从 MSYS bash 安装了这个package。它将所有内容安装在...\msys2\mingw64中。 You get clang 10 (+ gcc 9.3) and all the needed stl headers (still no c++20 headers like <concepts> though).你得到 clang 10 (+ gcc 9.3) 和所有需要的 stl 标头(虽然仍然没有像<concepts>这样的 c++20 标头)。

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

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