且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用CMake和clang在Windows上构建一个简单的C ++项目

更新时间:2023-11-10 19:21:22

如果我没记错的话,Clang默认会尝试在Windows上使用MSVC的标准库,因为Clang自己的标准库在Windows上尚不可用.

If I remember correctly, Clang attempts to use MSVC's standard library on Windows by default, since Clang's own standard library doesn't work on Windows yet.

如果您没有安装MSVC,则会导致问题.

If you don't have MSVC installed, this causes problems.

最简单的解决方案是安装MSYS2并使用MSYS2的修补Clang,默认情况下使用GCC的库.作为一个不错的奖励,MSYS2还附带了最新的GCC版本.

The easiest solution is to install MSYS2 and use MSYS2's patched Clang, which uses GCC's libraries by default. As a nice bonus, MSYS2 also comes with an up-to-date GCC version.

或者,您可以使用 -target 标志告诉Clang使用GCC的库.如果我没记错的话,可以通过在编译器和链接器标志中添加 -target x86_64-w64-mingw32 来完成.

Alternatively, you can use -target flag to tell Clang to use GCC's libraries. If I remember correctly, this is done by adding -target x86_64-w64-mingw32 to both compiler and linker flags.

(如果不起作用,请尝试 -target x86_64-w64-windows-gnu ,我不记得它是哪一个.将 x86_64 替换为 i686 (如果您使用的是32位编译器.)

(If it doesn't work, try -target x86_64-w64-windows-gnu, I can't remember which one it is. Replace x86_64 with i686 if you're using a 32-bit compiler.)