简体   繁体   中英

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.

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:

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):

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:

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 . Maybe there's a version for x86_64-pc-windows-gnu that I should use instead? Is there any way to make this work at this moment, or should I wait for support from MSVC? Is there maybe any alternative besides MSVC and MinGW?

Based on @HolyBlackCat 's sugestion, I tried this with MSYS2 and it works perfectly. I simply installed MSYS2, then from the MSYS bash I installed this package. It installs everything in in ...\msys2\mingw64 . You get clang 10 (+ gcc 9.3) and all the needed stl headers (still no c++20 headers like <concepts> though).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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