太难了!制作交叉编译器 x86_64-w64-mingw32-gcc 踩坑记录
2025-06-19 23:39:16

研究 GCC 交叉编译器有些天了,相关的资料不算很多,可能是因为太折腾了,这个话题没有太多人讨论。没有特别需求的话大家更愿意用系统自带的交叉编译器,开箱即用。


网络上相关资料更多都是在制作 Linux x86_64 和 Linux arm64 之间的交叉编译器,我也尝试过,但流程很复杂,每个人的编译环境又不同,很容易编译失败。
因为我平时主要在 Windows 平台上工作,所以尝试在 Linux 上编译一个 Windows 上运行的 GCC,经过无数次编译失败,耗费N个小时后,终于成功了!


首先有些基本概念要了解一下:

  • 有个工具包叫Binutils,它是汇编器、链接器的源码,是必须要编译的,它不依赖 glibc 和 Linux 头文件。比较独立,所以编译一般不会出问题。
  • 如果目标是 Linux 平台,则编译过程比较复杂,gcc、glibc要分阶段编译,比较复杂,容易失败。而目标平台是 Windows 的话则简单很多。

第一次失败了

这是一次失败的编译,可以选择是否阅读,其中有坑点,可以看看。

准备

我的编译环境是 Ubuntu 20.04 x86_64
目标环境是 Windows amd64


Binutils 版本选择的是 2.44:https://mirrors.ustc.edu.cn/gnu/binutils/
GCC 版本选择的是 15.1.0:https://mirrors.ustc.edu.cn/gnu/gcc/gcc-15.1.0
然后提前安装好相应的工具:

1
sudo apt install make texinfo mingw-w64-x86-64-dev -y

如果要编译32位程序的话就安装mingw-w64-i686-dev包,或者直接安装包含两者的mingw-w64

编译 Binutils

1
2
3
4
5
6
7
cd /opt
tar xf binutils-2.44.tar.xz
cd binutils-2.44/
mkdir build && cd build
../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 --disable-multilib --disable-nls --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
make -j$(nproc)
make install-strip

编译 GCC

1
2
3
4
5
6
7
cd /opt
tar xf gcc-15.1.0.tar.xz
cd gcc-15.1.0/
./contrib/download_prerequisites
mkdir build && cd build
../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 -with-sysroot=/usr/x86_64-w64-mingw32 --enable-languages=c,c++ --enable-threads=win32 --enable-shared --disable-multilib --disable-werror --disable-checking --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
make -j$(nproc)

开始漫长的等待过程了。。。
不出意外的话会碰到一个错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if [ -d ../prev-gcc ]; then \
cd ../prev-gcc && \
make real-install-headers-tar DESTDIR=`pwd`/../gcc/ \
libsubdir=. ; \
else \
set -e; for ml in `cat fixinc_list`; do \
sysroot_headers_suffix=`echo ${ml} | sed -e 's/;.*$//'`; \
multi_dir=`echo ${ml} | sed -e 's/^[^;]*;//'`; \
fix_dir=include-fixed${multi_dir}; \
if ! false && test ! -d `echo /usr/x86_64-w64-mingw32${sysroot_headers_suffix}/mingw/include | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta`; then \
echo "The directory (BUILD_SYSTEM_HEADER_DIR) that should contain system headers does not exist:" >&2 ; \
echo " `echo /usr/x86_64-w64-mingw32${sysroot_headers_suffix}/mingw/include | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta`" >&2 ; \
case linux-gnu in \
darwin*) \
echo "(on Darwin this usually means you need to pass the --with-sysroot= flag to point to a valid MacOS SDK)" >&2; \
;; \
esac; \
tooldir_sysinc=`echo "/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/sys-include" | sed -e :a -e "s,[^/]*/\.\.\/,," -e ta`; \
if test "x`echo /usr/x86_64-w64-mingw32${sysroot_headers_suffix}/mingw/include | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta`" = "x${tooldir_sysinc}"; \
then sleep 1; else exit 1; fi; \
fi; \
/bin/bash ../../gcc/../mkinstalldirs ${fix_dir}; \
chmod a+rx ${fix_dir} || true; \
(TARGET_MACHINE='x86_64-w64-mingw32'; srcdir=`cd ../../gcc; ${PWDCMD-pwd}`; \
SHELL='/bin/bash'; MACRO_LIST=`${PWDCMD-pwd}`/macro_list ; \
gcc_dir=`${PWDCMD-pwd}` ; \
export TARGET_MACHINE srcdir SHELL MACRO_LIST && \
cd ../build-x86_64-linux-gnu/fixincludes && \
/bin/bash ./fixinc.sh "${gcc_dir}/${fix_dir}" \
`echo /usr/x86_64-w64-mingw32${sysroot_headers_suffix}/mingw/include | sed -e :a -e 's,[^/]*/\.\.\/,,' -e ta` ); \
done; \
fi
The directory (BUILD_SYSTEM_HEADER_DIR) that should contain system headers does not exist:
/usr/x86_64-w64-mingw32/mingw/include
make[2]: *** [Makefile:3643: stmp-fixinc] Error 1
make[2]: *** Waiting for unfinished jobs....
rm gcc.pod
make[2]: Leaving directory '/opt/gcc-15.1.0/build/gcc'
make[1]: *** [Makefile:4728: all-gcc] Error 2
make[1]: Leaving directory '/opt/gcc-15.1.0/build'
make: *** [Makefile:1068: all] Error 2

Makefile 文件中硬编码了一个规则:它强制性地在sysroot路径 (/usr/x86_64-w64-mingw32) 后面拼接上了一个/mingw/include子目录,然后检查这个拼接成的路径是否存在。
因为我编译的 GCC 版本较新,而通过系统安装的 mingw-w64 版本较低(7.0),目录结构不同,导致 GCC 找不到相关的头文件。

1
2
3
$ dpkg -l | grep mingw-w64
ii mingw-w64-common 7.0.0-2 all Common files for Mingw-w64
ii mingw-w64-x86-64-dev 7.0.0-2 all Development files for MinGW-w64 targeting Win64

解决办法是在 GCC 期望的位置创建软连接:

1
2
3
4
5
6
7
8
# 创建它期望的 /mingw 父目录
sudo mkdir -p /usr/x86_64-w64-mingw32/mingw

# 创建一个名为 include 的符号链接,指向真实的 include 目录
sudo ln -s /usr/x86_64-w64-mingw32/include /usr/x86_64-w64-mingw32/mingw/include

# 为 lib 目录也创建一个,以防后面链接阶段出现类似问题
sudo ln -s /usr/x86_64-w64-mingw32/lib /usr/x86_64-w64-mingw32/mingw/lib

最后安装

1
make install-strip

检验

1
2
3
4
5
6
7
8
9
$ /opt/x86_64-w64-mingw32-gcc15/bin/x86_64-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/x86_64-w64-mingw32-gcc15/bin/x86_64-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/opt/x86_64-w64-mingw32-gcc15/libexec/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 -with-sysroot=/usr/x86_64-w64-mingw32 --enable-languages=c,c++ --enable-threads=win32 --enable-shared --disable-multilib --disable-werror --disable-checking --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
Thread model: win32
Supported LTO compression algorithms: zlib
gcc version 15.1.0 (GCC)

写个例子程序试试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <thread>
#include <format>

void printHello() {
auto s = std::format("{} {}\n", "Hello" , 123);
std::cout << s;
}

int main() {
std::thread t(printHello);
t.join();
return 0;
}

编译报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ /opt/x86_64-w64-mingw32-gcc15/bin/x86_64-w64-mingw32-g++ -std=c++23 main.cpp -o main
main.cpp: In function ‘int main()’:
main.cpp:14:29: error: no matching function for call to ‘std::thread::thread(void (&)())’
14 | std::thread t(printHello);
| ^
main.cpp:14:29: note: there are 2 candidates
In file included from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/stop_token:40,
from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/thread:44,
from main.cpp:5:
/opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/bits/std_thread.h:189:5: note: candidate 1: ‘std::thread::thread(std::thread&&)’
189 | thread(thread&& __t) noexcept
| ^~~~~~
/opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/bits/std_thread.h:189:21: note: no known conversion for argument 1 from ‘void()’ to ‘std::thread&&’
189 | thread(thread&& __t) noexcept
| ~~~~~~~~~^~~
/opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/bits/std_thread.h:143:5: note: candidate 2: ‘std::thread::thread()’
143 | thread() noexcept = default;
| ^~~~~~
/opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/bits/std_thread.h:143:5: note: candidate expects 0 arguments, 1 provided

掉坑里了,因为 mingw-w64 版本太老了。看来需要自行编译mingw-w64

第二次成功了

Ubuntu 20 系统中安装的 mingw-w64 版本是 7.0.0,版本有点老了。我们可以去官网下载目前最新的 13.0.0:https://www.mingw-w64.org/source/
将前面安装的mingw-w64-x86-64-dev删掉,避免在编译过程中不小心引入了老的头文件或库。

1
sudo apt-get remove --purge mingw-w64-x86-64-dev

编译 Binutils

和前面的步骤一模一样

1
2
3
4
5
6
7
cd /opt
tar xf binutils-2.44.tar.xz
cd binutils-2.44/
mkdir build && cd build
../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 --disable-multilib --disable-nls --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
make -j$(nproc)
make install-strip

安装 mingw-w64 头文件

这里先看看帮助

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 注意,我们指向的是 mingw-w64-headers 子目录下的 configure 脚本
cd /opt/mingw-w64-v13.0.0/mingw-w64-headers
mkdir build && cd build

$ ../configure -h
'configure' configures mingw-w64-headers 4.0b to adapt to many kinds of systems.

Usage: ../configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print 'checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for '--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or '..']

Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]

By default, 'make install' will install all the files in
'/usr/local/bin', '/usr/local/lib' etc. You can specify
an installation prefix other than '/usr/local' using '--prefix',
for instance '--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root
[DATAROOTDIR/doc/mingw-w64-headers]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]

Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names

System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]

Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-silent-rules less verbose build output (undo: "make V=1")
--disable-silent-rules verbose build output (undo: "make V=0")
--enable-maintainer-mode
enable make rules and dependencies not useful (and
sometimes confusing) to the casual installer
--enable-w32api Enable building a w32api package for Cygwin
(shorthand for --includedir=PREFIX/include/w32api
--disable-crt)
--disable-crt Do not use the default crt headers
--enable-sdk=ARG Add the desired SDK, where ARG can be one of ddk, no
or all. Default is all.
--enable-idl Enable installing idl files

Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-widl=PATH use widl to update idl-based headers. Optionally
search for a compatible widl in PATH
--with-default-win32-winnt=VER
Default value of _WIN32_WINNT (default: 0xa00)
--with-default-msvcrt=LIB
Default msvcrt to target (default: ucrt)

有两个参选项得注意:--with-default-win32-winnt--with-default-msvcrt
--with-default-win32-winnt决定了支持最低的 Windows API,这里的默认值是0x0A00,表示 Windows 10,有些高了,因为我要求兼容至 Vista,那么要改为0x0600,其他值查看微软手册:更新 WINVER 和 _WIN32_WINNT
--with-default-msvcrt决定了运行时类型,默认是ucrt,意味着最终编译出的程序会依赖一堆api-ms开头的 DLL 文件,这需要用户电脑安装 VC 运行库,这是默认且推荐的方式。
如果要用老的运行时msvcrt,就将选项改为--with-default-msvcrt=msvcrt即可。

1
2
../configure --prefix=/opt/sysroot/mingw --with-default-win32-winnt=0x0600 --with-default-msvcrt=msvcrt --build=x86_64-linux-gnu --host=x86_64-w64-mingw32
make install-strip

msvcrt的好处是不需要额外安装 VC Runtime,仅依赖msvcrt.dll,特别是编译 32 位程序的话,可以运行在 XP 系统上。

第一次编译 GCC

有了上面的头文件后,可以编译 GCC 了,第一次只编译“纯净”的 GCC,它的作用仅用于编译mingw-w64运行时

1
2
3
4
5
../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 -with-sysroot=/opt/sysroot --enable-languages=c --disable-shared --disable-threads --disable-libstdcxx --disable-multilib --disable-werror --disable-checking --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
make -j$(nproc) all-gcc
make install-strip-gcc
make -j$(nproc) all-target-libgcc
make install-strip-target-libgcc

编译 mingw-w64 运行时

从这一步开始,我们需要用到刚才制作的 GCC 编译器了,所以将bin目录添加到PATH环境变量中:

1
export PATH=/opt/x86_64-w64-mingw32-gcc15/bin:$PATH

验证一下

1
2
$ which x86_64-w64-mingw32-gcc
/opt/x86_64-w64-mingw32-gcc15/bin/x86_64-w64-mingw32-gcc

OK,没问题。开始编译完整的mingw-w64

1
2
3
4
5
cd /opt/mingw-w64-v13.0.0/mingw-w64-crt
mkdir build && cd build
../configure --prefix=/opt/sysroot/mingw --with-default-msvcrt=msvcrt --build=x86_64-linux-gnu --host=x86_64-w64-mingw32
make -j$(nproc)
make install-strip

第二次编译 GCC

这是最后一步,编译完整的 GCC。注意编译时新建一个文件夹,不要在第一次的 build 目录中进行

1
2
3
4
5
cd /opt/gcc-15.1.0/
mkdir build-gcc-final && cd build-gcc-final
../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 -with-sysroot=/opt/sysroot --enable-languages=c,c++ --enable-threads=win32 --enable-shared --disable-multilib --disable-werror --disable-checking --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
make -j$(nproc)
make install-strip

大功告成!再次编译示例程序

1
/opt/x86_64-w64-mingw32-gcc15/bin/x86_64-w64-mingw32-g++ -std=c++23 main.cpp -o main

终于得到一个可以运行的 exe 程序了!
本质上我们从零开始制作了一份mingw-w64-x86-64-dev包!

事情还没完

当我将前面制作好的工具链打包为.deb文件后,还原了虚拟机,然后安装这个工具链,再次编译示例程序,报错了!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$ x86_64-w64-mingw32-g++ -std=c++23 main.cpp -o main -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/opt/x86_64-w64-mingw32-gcc15/libexec/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../configure --prefix=/opt/x86_64-w64-mingw32-gcc15 -with-sysroot=/opt/sysroot --enable-languages=c,c++ --enable-threads=win32 --enable-shared --disable-multilib --disable-werror --disable-checking --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-w64-mingw32
Thread model: win32
Supported LTO compression algorithms: zlib
gcc version 15.1.0 (GCC)
COLLECT_GCC_OPTIONS='-std=c++23' '-o' 'main.exe' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/x86_64-w64-mingw32-gcc15/libexec/gcc/x86_64-w64-mingw32/15.1.0/cc1plus -quiet -v -U_REENTRANT main.cpp -quiet -dumpbase main.cpp -dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++23 -version -o /tmp/ccPJxgCO.s
GNU C++23 (GCC) version 15.1.0 (x86_64-w64-mingw32)
compiled by GNU C version 9.4.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/sysroot/usr/local/include"
ignoring nonexistent directory "/opt/sysroot/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include/c++/15.1.0
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include/c++/15.1.0/x86_64-w64-mingw32
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include/c++/15.1.0/backward
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/include
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/include-fixed
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include
End of search list.
Compiler executable checksum: c6785f47bdf27eacd276f07e706187db
In file included from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/bits/postypes.h:42,
from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/iosfwd:44,
from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/ios:42,
from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/bits/ostream.h:43,
from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/ostream:42,
from /opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/iostream:43,
from main.cpp:4:
/opt/x86_64-w64-mingw32-gcc15/x86_64-w64-mingw32/include/c++/15.1.0/cwchar:49:10: fatal error: wchar.h: No such file or directory
49 | #include <wchar.h>
| ^~~~~~~~~
compilation terminated.

看上去是因为打包时没有将sysroot打包进来,也就是 mingw-w64 的头文件和运行时。
从详细日志上看,gcc 会从编译时指定的--with-sysroot参数中搜索

1
2
ignoring nonexistent directory "/opt/sysroot/usr/local/include"
ignoring nonexistent directory "/opt/sysroot/mingw/include"

从 gcc 的搜索路径来看

1
2
3
4
5
6
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include/c++/15.1.0
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include/c++/15.1.0/x86_64-w64-mingw32
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include/c++/15.1.0/backward
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/include
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/include-fixed
/opt/x86_64-w64-mingw32-gcc15/lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/include

前面 5 个都是和 C++ 相关的路径,而最后一个返回到了工具链安装根目录下的x86_64-w64-mingw32/include,其实这里对于 gcc 来说就像是/usr目录一样,gcc 默认会在这里搜索头文件和库。
所以我们要做的就是将mingw-w64的头文件和运行时安装到这个目录下再打包即可。

相关阅读

「天龙八部」年轻人的第一个GCC交叉编译器

上一页
2025-06-19 23:39:16