简介
起因:
- 我在使用 go 编写的程序,用到 SQLite 数据库
- 在 Windows 平台使用 SQLite 需要有 gcc 环境,
不过,Windows 上使用 gcc 还真是麻烦,搜索引擎搜出来的答案不尽人意,有的过时,有的下载后报毒。
花了一番功夫,总算找到了一个很好的安装 gcc 环境的方法。
下载
这里使用 Github 下载的软件,无毒
下载地址:https://github.com/niXman/mingw-builds-binaries/releases/tag/14.2.0-rt_v12-rev1
选择 x86_64-14.2.0-release-mcf-seh-ucrt-rt_v12-rev1.7z
即可
解压,加入环境变量,终端运行
结果显示如下,表示 gcc 可用
1
2
3
4
5
6
7
8
|
Using built-in specs.
COLLECT_GCC=D:\develop\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=D:/develop/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/14.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-14.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/buildroot/x86_64-1420-mcf-seh-ucrt-rt_v12-rev1/mingw64 --enable-host-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=mcf --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-libssp --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/buildroot/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-mcf-seh-rev1, Built by MinGW-Builds project' --with-bugurl=https://github.com/niXman/mingw-builds LD_FOR_TARGET=/c/buildroot/x86_64-1420-mcf-seh-ucrt-rt_v12-rev1/mingw64/bin/ld.exe --with-boot-ldflags='-pipe -fno-ident -L/c/buildroot/x86_64-1420-mcf-seh-ucrt-rt_v12-rev1/mingw64/opt/lib -L/c/buildroot/prerequisites/x86_64-zlib-static/lib -L/c/buildroot/prerequisites/x86_64-w64-mingw32-static/lib -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc'
Thread model: mcf
Supported LTO compression algorithms: zlib
gcc version 14.2.0 (x86_64-mcf-seh-rev1, Built by MinGW-Builds project)
|
版本选择
mcf
vs. posix
: 这涉及到编译器和标准库的实现。
mcf
: 这可能指的是 MinGW Cross Framework,它是一个用于在 Windows 上构建 Unix 风格程序的工具集。 mcf
版本通常更倾向于与 MinGW 环境集成。
posix
: POSIX (Portable Operating System Interface) 是一组标准,旨在确保不同操作系统之间的软件可移植性。 posix
版本通常更倾向于遵循 POSIX 标准,并且可能包含一些与 POSIX 兼容的库。
ucrt
vs. msvcrt
: 这指的是 C 运行时库。
ucrt
: Universal C Runtime,是 Windows 10 及更高版本上的标准 C 运行时库。它是 Windows 操作系统的核心组件。
msvcrt
: Microsoft Visual C++ Runtime Library,是旧版本的 Windows 上使用的 C 运行时库。
你应该选择哪个?
- 如果你在 Windows 10 或更高版本上开发,并且希望使用最新的 C 运行时库,那么
ucrt
版本是更好的选择。 这是最常见的选择。
mcf-seh-ucrt-rt_v12-rev1.7z
可能是最适合你的,因为它明确使用了 ucrt
,并且 mcf
意味着它可能针对 MinGW 环境进行了优化。
posix
版本通常用于需要跨平台兼容性的项目。除非你有明确的需求,否则通常不需要 posix
版本。
msvcrt
版本通常用于支持旧版本的 Windows。除非你需要支持旧版本的 Windows,否则不需要 msvcrt
版本。
总结:
通常情况下,x86_64-14.2.0-release-mcf-seh-ucrt-rt_v12-rev1.7z
是一个好的选择,因为它使用了最新的 ucrt
运行时库。 如果你确实需要与 POSIX 兼容,那就选择带有 posix
和 ucrt
的版本。 除非你需要支持非常旧的 Windows 版本,否则避免使用 msvcrt
版本。