几种mingw使用记录

环境

  • windows 10 64位 专业版 1607(内部版本 14393.1715)
  • mingw 多年前装的版本,但使用在线安装器 到了最新
  • nuwen mingw 下载地址
  • TDM-GCC-64 下载地址
  • mingw-w64 本来想也测下这个的,但是没下载动,算了。。。

    mingw gcc -v

    1
    2
    3
    4
    5
    6
    7
     specs
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=d:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
    mingw32
    ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
    win32
    gcc 6.3.0 (MinGW.org GCC-6.3.0-1)

TDM-GCC-64 gcc -v

1
2
3
4
5
6
7
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/TDM-GCC-64/bin/../libexec/gcc/x86_64-w64-mingw32/5.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-5.1.0/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: posix
gcc version 5.1.0 (tdm64-1)

nuwen gcc -v

1
2
3
4
5
6
7
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=d:/mingw-nuwen-15.1/bin/../libexec/gcc/x86_64-w64-mingw32/7.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../src/configure --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-multilib --prefix=/c/temp/gcc/dest --with-sysroot=/c/temp/gcc/dest --disable-libstdcxx-pch --disable-libstdcxx-verbose --disable-nls --disable-shared --disable-win32-registry --with-tune=haswell
Thread model: win32
gcc version 7.2.0 (GCC)

简单测试

先创建一个简单的c文件:

1
echo void main(){} > simple.c

然后使用不同的mingw环境来执行gcc进行编译链接,分别使用默认参数、-m32、-m64做测试。

mingw

  • gcc simple.c -o simple-gcc.exe 无输出,生成32位exe
  • gcc simple.c -o simple-gcc-m32.exe -m32 无输出,生成32位exe
  • gcc simple.c -o simple-gcc-m64.exe -m64 命令直接出错

    simple.c:1:0: 对不起,尚未实现:未编译入对 64 位模式的支持
    void main(){}

nuwen

  • gcc simple.c -o simple-nuwen.exe 无输出,生成64位exe
  • gcc simple.c -o simple-nuwen-m64.exe -m64 无输出,生成64位exe
  • gcc simple.c -o simple-nuwen-m32.exe -m32 链接出错

    d:/mingw-nuwen-15.1/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/mingw-nuwen-15.1/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/libmingw32.a when searching for -lmingw32
    …-lgcc、-lmoldname、-lmingwex、-lmsvcrt、-ladvapi32、-lshell32、-lkernel32…
    x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/libmsvcrt.a when searching for -lmsvcrt
    d:/mingw-nuwen-15.1/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmsvcrt
    collect2.exe: error: ld returned 1 exit status

TDM-GCC-64

  • gcc simple.c -o simple-tdm.exe 无输出,生成64位exe
  • gcc simple.c -o simple-tdm-m64.exe -m64 无输出,生成64位exe
  • gcc simple.c -o simple-tdm-m32.exe -m32 无输出,生成32位exe

某项目用到了glibc,所以使用glibc再测一次

使用glibc 2.28版本,下载地址

上面编译失败的就不再尝试了,只尝试上面成功过的。

使用测试代码:

1
2
3
4
5
6
7
#include <glib.h>

void main() {

char* buffer = (char *)g_malloc(100);
g_free(buffer);
}

MinGW -m32

1
2
3
gcc test.c -ID:\VC_INCLUDE\glibc-2.28.8\include\glib-2.0 -ID:\VC_INCLUDE\glibc-2.28.8\lib\glib-2.0\include  D:\VC_INCLUDE\glibc-2.28.8\bin\libglib-2.0-0.dll -o test-gcc.exe
====>
编译成功,生成32位exe

TDM-GCC-64 -m32

1
2
3
gcc test.c -ID:\VC_INCLUDE\glibc-2.28.8\include\glib-2.0 -ID:\VC_INCLUDE\glibc-2.28.8\lib\glib-2.0\include  D:\VC_INCLUDE\glibc-2.28.8\bin\libglib-2.0-0.dll -o test-tdm-m32.exe -m32
====>
编译成功,生成32位exe

TDM-GCC-64 不使用-m32 链接出错(没有glibc的64位lib)

1
2
3
4
5
gcc test.c -ID:\VC_INCLUDE\glibc-2.28.8\include\glib-2.0 -ID:\VC_INCLUDE\glibc-2.28.8\lib\glib-2.0\include  D:\VC_INCLUDE\glibc-2.28.8\bin\libglib-2.0-0.dll -o test-tdm.exe
====>
C:\Users\terry\AppData\Local\Temp\ccA3V4Ba.o:test.c:(.text+0x13): undefined reference to `g_malloc'
C:\Users\terry\AppData\Local\Temp\ccA3V4Ba.o:test.c:(.text+0x23): undefined reference to `g_free'
collect2.exe: error: ld returned 1 exit status

nuwen 链接出错 (没有glibc的64位lib)

1
2
3
4
5
gcc test.c -ID:\VC_INCLUDE\glibc-2.28.8\include\glib-2.0 -ID:\VC_INCLUDE\glibc-2.28.8\lib\glib-2.0\include  D:\VC_INCLUDE\glibc-2.28.8\bin\libglib-2.0-0.dll -o test-nuwen.exe
====>
C:\Users\terry\AppData\Local\Temp\ccedeuKo.o:test.c:(.text+0x13): undefined reference to `g_malloc'
C:\Users\terry\AppData\Local\Temp\ccedeuKo.o:test.c:(.text+0x23): undefined reference to `g_free'
collect2.exe: error: ld returned 1 exit status

总结

反正TDM-GCC-64这个最好使,默认下载下来就支持32位和64位的gcc编译,其它的估计都得自己再折腾。但nuwen的优势是版本更新快,自带的3方库最多。