相关文件下载链接:

13.2.0版的MinGW64
3.2.4版的wxwidgets

相关环境变量设置:右键单击“我的电脑”->属性->高级系统设置->环境变量->系统变量->Path->编辑->新建,输入解压后的mingw64中的bin路径。例如:

D:\devolopment\mingw64\bin\

测试成功安装与否,在上述环境变量设置好后,重新进入终端中,执行GCC命令:

gcc -v
Using built-in specs.
COLLECT_GCC=D:\devolopment\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=D:/devolopment/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-w64-mingw32
Configured with: ../configure --prefix=/R/winlibs64ucrt_stage/inst_gcc-13.2.0/share/gcc --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-offload-targets=nvptx-none --with-pkgversion='MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders, r7' --with-tune=generic --enable-checking=release --enable-threads=posix --disable-sjlj-exceptions --disable-libunwind-exceptions --disable-serial-configure --disable-bootstrap --enable-host-shared --enable-plugin --disable-default-ssp --disable-rpath --disable-libstdcxx-debug --disable-version-specific-runtime-libs --with-stabs --disable-symvers --enable-languages=c,c++,fortran,lto,objc,obj-c++ --disable-gold --disable-nls --disable-stage1-checking --disable-win32-registry --disable-multilib --enable-ld --enable-libquadmath --enable-libada --enable-libssp --enable-libstdcxx --enable-lto --enable-fully-dynamic-string --enable-libgomp --enable-graphite --enable-mingw-wildcard --enable-libstdcxx-time --enable-libstdcxx-pch --with-mpc=/d/Prog/winlibs64ucrt_stage/custombuilt --with-mpfr=/d/Prog/winlibs64ucrt_stage/custombuilt --with-gmp=/d/Prog/winlibs64ucrt_stage/custombuilt --with-isl=/d/Prog/winlibs64ucrt_stage/custombuilt --disable-libstdcxx-backtrace --enable-install-libiberty --enable-__cxa_atexit --without-included-gettext --with-diagnostics-color=auto --enable-clocale=generic --with-libiconv --with-system-zlib --with-build-sysroot=/R/winlibs64ucrt_stage/gcc-13.2.0/build_mingw/mingw-w64 CFLAGS='-I/d/Prog/winlibs64ucrt_stage/custombuilt/include/libdl-win32   -march=nocona -msahf -mtune=generic -O2' CXXFLAGS='-Wno-int-conversion  -march=nocona -msahf -mtune=generic -O2' LDFLAGS='-pthread -Wl,--no-insert-timestamp -Wl,--dynamicbase -Wl,--high-entropy-va -Wl,--nxcompat -Wl,--tsaware' LD=/d/Prog/winlibs64ucrt_stage/custombuilt/share/binutils/bin/ld.exe
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders, r7)

1.主要编译参数如下表:

变量   含义   值   含义
BUILD 控制编译wxWidgets是debug版本或release版本,debug版本时,库名带后缀d. debug  生成debug库,后缀有d
release  生成release库
SHARED 控制编译wxWidgets成DLL或是static, DLL时,多个wxWidgets工程可共用相同的DLL,工程发布时,必须包含该DLL文件 0 生成static静态链接库文件
1 生成dll链接文件
MONOLITHIC 控制编译成1个独立的DLL库,还是多个DLL库 0 生成分离的多文件库(缺省值)
1 将所有库编译成一个单独库文件
UNICODE 控制编译出的wxWidgets是否支持unicode,若使用汉字,必须支持unicode 0 不支持uncode编码
1 支持uncode编码

2.编制编译批处理文件

mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=release 
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release 
mingw32-make -f makefile.gcc SHARED=0 UNICODE=0 BUILD=release 
mingw32-make -f makefile.gcc SHARED=1 UNICODE=0 BUILD=release 
mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=debug 
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=debug 
mingw32-make -f makefile.gcc SHARED=0 UNICODE=0 BUILD=debug 
mingw32-make -f makefile.gcc SHARED=1 UNICODE=0 BUILD=debug 

3.清理编译的垃圾文件

mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=release clean
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release clean
mingw32-make -f makefile.gcc SHARED=0 UNICODE=0 BUILD=release clean
mingw32-make -f makefile.gcc SHARED=1 UNICODE=0 BUILD=release clean
mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=debug clean
mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=debug clean
mingw32-make -f makefile.gcc SHARED=0 UNICODE=0 BUILD=debug clean
mingw32-make -f makefile.gcc SHARED=1 UNICODE=0 BUILD=debug clean

进入到wxWidgets\3.2.4\build\msw\文件夹中,运行上述相应的批处理文件等待编译完成即可。我是睡觉前开着电脑开始编译,早上就已经编译完成。

注意:

1.如果用gcc直接编译单独的c文件,不要用-o参数,直接编译C源文件即可,例如:

gcc -c helloworld.c
而不是
gcc -c helloworld.c -o helloworld.exe
这是让编译器自动根据宿主机器自动选择对应系统,否则会出现“程序“helloworld.exe”无法运行: 指定的可执行文件不是此操作系统平台的有效应用程序。”的错误。

2.如果要编译示例,直接入到对应示例文件夹中,执行:

mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=release 

上述命令生成的执行文件在示例文件夹下的gcc_mswu下。