所以我一直在尝试编译最新的 gcc 版本大约 20 小时,我似乎无法弄清楚是什么导致了错误。我在自定义 Windows 64 位计算机上使用 MSYS2 msys 进行以下操作。编译 gcc 所需的 gcc 编译器可执行文件附带 Code::Blocks IDE 的二进制版本 20.03。
这就是我所做的:
objdir=c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64
srcdir=c/Programming/GNU/GCC/GCC_11.2.0/source/gcc-11.2.0
cd objdir
export PATH=/path/to/gcc_compiler_executable:$PATH
make distclean
../../source/gcc-11.2.0/contrib/download_prerequisites
../../source/gcc11.2.0/configure --enable-bootstrap --disable-shared --prefix=objdir --enable-gold --host=x86_64-pc-mingw64 --target=x86_64-pc-mingw64
最后一个函数输出:
configure: loading site script /etc/config.site
checking build system type... x86_64-pc-msys
checking host system type... x86_64-pc-mingw64
checking target system type... x86_64-pc-mingw64
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... no, using cp -pR
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... no
checking for libsanitizer support... no
checking for libvtv support... yes
checking for libhsail-rt support... no
checking for libphobos support... no
checking for x86_64-pc-mingw64-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.exe
checking for suffix of executables... .exe
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for x86_64-pc-mingw64-g++... no
checking for x86_64-pc-mingw64-c++... no
checking for x86_64-pc-mingw64-gpp... no
checking for x86_64-pc-mingw64-aCC... no
checking for x86_64-pc-mingw64-CC... no
checking for x86_64-pc-mingw64-cxx... no
checking for x86_64-pc-mingw64-cc++... no
checking for x86_64-pc-mingw64-cl.exe... no
checking for x86_64-pc-mingw64-FCC... no
checking for x86_64-pc-mingw64-KCC... no
checking for x86_64-pc-mingw64-RCC... no
checking for x86_64-pc-mingw64-xlC_r... no
checking for x86_64-pc-mingw64-xlC... no
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... yes
checking for x86_64-pc-mingw64-gnatbind... no
checking for gnatbind... no
checking for x86_64-pc-mingw64-gnatmake... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... tail -c +17 $$f1 > tmp-foo1; tail -c +17 $$f2 > tmp-foo2; cmp tmp-foo1 tmp-foo2
configure: WARNING: trying to bootstrap a cross compiler
checking for objdir... .libs
configure: WARNING: using in-tree isl, disabling version check
The following languages will be built: c,c++,fortran,lto,objc
*** This configuration is not supported in the following subdirectories:
target-libgomp target-libitm target-libsanitizer target-libphobos target-libffi target-libgo gnattools gotools target-libada target-libhsail-rt target-zlib target-liboffloadmic
(Any other directories should still work fine.)
checking for default BUILD_CONFIG...
checking for --enable-vtable-verify... no
checking for bison... no
checking for byacc... no
checking for yacc... no
checking for bison... no
checking for gm4... no
checking for gnum4... no
checking for m4... no
checking for flex... no
checking for lex... no
checking for flex... no
checking for makeinfo... no
/c/Programming/GNU/GCC/GCC_11.2.0/source/gcc-11.2.0/missing: line 81: makeinfo: command not found
checking for expect... no
checking for runtest... no
checking for x86_64-pc-mingw64-ar... no
checking for x86_64-pc-mingw64-as... no
checking for x86_64-pc-mingw64-dlltool... no
checking for ld... (cached) C:/Programming/Editors/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe
checking for x86_64-pc-mingw64-ld... (cached) C:/Programming/Editors/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe
checking for x86_64-pc-mingw64-lipo... no
checking for x86_64-pc-mingw64-nm... no
checking for x86_64-pc-mingw64-ranlib... no
checking for x86_64-pc-mingw64-strip... no
checking for x86_64-pc-mingw64-windres... no
checking for x86_64-pc-mingw64-windmc... no
checking for x86_64-pc-mingw64-objcopy... no
checking for x86_64-pc-mingw64-objdump... no
checking for x86_64-pc-mingw64-otool... no
checking for x86_64-pc-mingw64-readelf... no
checking for x86_64-pc-mingw64-cc... no
checking for x86_64-pc-mingw64-gcc... no
checking for x86_64-pc-mingw64-c++... no
checking for x86_64-pc-mingw64-g++... no
checking for x86_64-pc-mingw64-cxx... no
checking for x86_64-pc-mingw64-gxx... no
checking for x86_64-pc-mingw64-gcc... no
checking for x86_64-pc-mingw64-gfortran... no
checking for x86_64-pc-mingw64-gccgo... no
checking for x86_64-pc-mingw64-gdc... no
checking for x86_64-pc-mingw64-ar... no
checking for x86_64-pc-mingw64-as... no
checking for x86_64-pc-mingw64-dlltool... no
checking for x86_64-pc-mingw64-ld... no
checking for x86_64-pc-mingw64-lipo... no
checking for x86_64-pc-mingw64-nm... no
checking for x86_64-pc-mingw64-objcopy... no
checking for x86_64-pc-mingw64-objdump... no
checking for x86_64-pc-mingw64-otool... no
checking for x86_64-pc-mingw64-ranlib... no
checking for x86_64-pc-mingw64-readelf... no
checking for x86_64-pc-mingw64-strip... no
checking for x86_64-pc-mingw64-windres... no
checking for x86_64-pc-mingw64-windmc... no
checking where to find the target ar... pre-installed
checking where to find the target as... pre-installed
checking where to find the target cc... pre-installed
checking where to find the target c++... pre-installed
checking where to find the target c++ for libstdc++... pre-installed
checking where to find the target dlltool... pre-installed
checking where to find the target gcc... pre-installed
checking where to find the target gfortran... pre-installed
checking where to find the target gccgo... pre-installed
checking where to find the target gdc... pre-installed
checking where to find the target ld... pre-installed
checking where to find the target lipo... pre-installed
checking where to find the target nm... pre-installed
checking where to find the target objcopy... pre-installed
checking where to find the target objdump... pre-installed
checking where to find the target otool... pre-installed
checking where to find the target ranlib... pre-installed
checking where to find the target readelf... pre-installed
checking where to find the target strip... pre-installed
checking where to find the target windres... pre-installed
checking where to find the target windmc... pre-installed
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile
之后,我运行:
make bootstrap-lean
在那里,我得到一个错误。这是我一直在努力的部分。
输出(开头被截断):
../libtool: line 1740: x86_64-pc-mingw64-ar: command not found
make[5]: *** [Makefile:477: libmpn.la] Error 127
make[5]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64/gmp/mpn'
make[4]: *** [Makefile:954: all-recursive] Error 1
make[4]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64/gmp'
make[3]: *** [Makefile:773: all] Error 2
make[3]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64/gmp'
make[2]: *** [Makefile:5845: all-stage1-gmp] Error 2
make[2]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64'
make[1]: *** [Makefile:27716: stage1-bubble] Error 2
make[1]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64'
make: *** [Makefile:28144: bootstrap-lean] Error 2
此错误出现在程序试图编译 GMP 文件的部分。
我已将错误范围缩小到在配置命令中设置了 --host 标签的事实,但如果我不设置该标签,它默认为 x86_64-pc-msys。它可以正常工作一段时间,但更进一步,我在 srcdir/libiberty/pex-unix.c 文件中收到一堆错误和警告,抱怨未解析的引用以及“this”变量干扰的事实C++ 'this'关键字'。--target 标签默认为相同的三元组 (x86_64-pc-msys)。
这是我所指的错误(开始被截断):
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'pex_wait':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:256:14: warning: implicit declaration of function 'wait'; did you mean 'cwait'? [-Wimplicit-function-declaration]
cpid = wait (status);
^~~~
cwait
../../../source/gcc-11.2.0/libiberty/pex-unix.c: At top level:
../../../source/gcc-11.2.0/libiberty/pex-unix.c:323:3: warning: initialization of 'pid_t (*)(struct pex_obj *, pid_t, int *, struct pex_time *, int, const char **, int *)' {aka 'long long int (*)(struct pex_obj *, long long int, int *, struct pex_time *, int, const char **, int *)'} from incompatible pointer type 'int (*)(struct pex_obj *, pid_t, int *, struct pex_time *, int, const char **, int *)' {aka 'int (*)(struct pex_obj *, long long int, int *, struct pex_time *, int, const char **, int *)'} [-Wincompatible-pointer-types]
pex_unix_wait,
^~~~~~~~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:323:3: note: (near initialization for 'funcs.wait')
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'save_and_install_fd':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:382:11: warning: implicit declaration of function 'fcntl'; did you mean 'fcvt'? [-Wimplicit-function-declaration]
flags = fcntl (old_fd, F_GETFD);
^~~~~
fcvt
../../../source/gcc-11.2.0/libiberty/pex-unix.c:382:26: error: 'F_GETFD' undeclared (first use in this function)
flags = fcntl (old_fd, F_GETFD);
^~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:382:26: note: each undeclared identifier is reported only once for each function it appears in
../../../source/gcc-11.2.0/libiberty/pex-unix.c:395:20: error: 'FD_CLOEXEC' undeclared (first use in this function); did you mean 'S_IEXEC'?
if ((flags & FD_CLOEXEC) == 0 && fcntl (old_fd, F_SETFD, FD_CLOEXEC) < 0)
^~~~~~~~~~
S_IEXEC
../../../source/gcc-11.2.0/libiberty/pex-unix.c:395:55: error: 'F_SETFD' undeclared (first use in this function)
if ((flags & FD_CLOEXEC) == 0 && fcntl (old_fd, F_SETFD, FD_CLOEXEC) < 0)
^~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:408:31: error: 'F_DUPFD' undeclared (first use in this function)
new_fd = fcntl (old_fd, F_DUPFD, 3);
^~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'restore_fd':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:442:19: error: 'FD_CLOEXEC' undeclared (first use in this function); did you mean 'S_IEXEC'?
if (flags & FD_CLOEXEC)
^~~~~~~~~~
S_IEXEC
../../../source/gcc-11.2.0/libiberty/pex-unix.c:444:29: error: 'F_SETFD' undeclared (first use in this function)
return fcntl (old_fd, F_SETFD, flags);
^~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'pex_unix_exec_child':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:526:42: warning: passing argument 3 of 'spawnvpe' from incompatible pointer type [-Wincompatible-pointer-types]
pid = spawnvpe (_P_NOWAITO, executable, (cc_cp)argv, (cc_cp)env);
^~~~~~~~~~~
In file included from C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/unistd.h:11,
from ../../../source/gcc-11.2.0/libiberty/pex-unix.c:40:
C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/process.h:193:67: note: expected 'char * const*' but argument is of type 'const char * const*'
intptr_t __cdecl spawnvpe(int,const char *_Filename,char *const _ArgList[],char *const _Env[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
~~~~~~~~~~~~^~~~~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:526:55: warning: passing argument 4 of 'spawnvpe' from incompatible pointer type [-Wincompatible-pointer-types]
pid = spawnvpe (_P_NOWAITO, executable, (cc_cp)argv, (cc_cp)env);
^~~~~~~~~~
In file included from C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/unistd.h:11,
from ../../../source/gcc-11.2.0/libiberty/pex-unix.c:40:
C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/process.h:193:90: note: expected 'char * const*' but argument is of type 'const char * const*'
intptr_t __cdecl spawnvpe(int,const char *_Filename,char *const _ArgList[],char *const _Env[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
~~~~~~~~~~~~^~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:528:41: warning: passing argument 3 of 'spawnve' from incompatible pointer type [-Wincompatible-pointer-types]
pid = spawnve (_P_NOWAITO, executable, (cc_cp)argv, (cc_cp)env);
^~~~~~~~~~~
In file included from C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/unistd.h:11,
from ../../../source/gcc-11.2.0/libiberty/pex-unix.c:40:
C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/process.h:191:66: note: expected 'char * const*' but argument is of type 'const char * const*'
intptr_t __cdecl spawnve(int,const char *_Filename,char *const _ArgList[],char *const _Env[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
~~~~~~~~~~~~^~~~~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:528:54: warning: passing argument 4 of 'spawnve' from incompatible pointer type [-Wincompatible-pointer-types]
pid = spawnve (_P_NOWAITO, executable, (cc_cp)argv, (cc_cp)env);
^~~~~~~~~~
In file included from C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/unistd.h:11,
from ../../../source/gcc-11.2.0/libiberty/pex-unix.c:40:
C:/Programming/Editors/CodeBlocks/MinGW/x86_64-w64-mingw32/include/process.h:191:89: note: expected 'char * const*' but argument is of type 'const char * const*'
intptr_t __cdecl spawnve(int,const char *_Filename,char *const _ArgList[],char *const _Env[]) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
~~~~~~~~~~~~^~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'pex_unix_wait':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:777:5: warning: implicit declaration of function 'kill'; did you mean 'tell'? [-Wimplicit-function-declaration]
kill (pid, SIGTERM);
^~~~
tell
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'pex_unix_pipe':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:795:10: warning: implicit declaration of function 'pipe'; did you mean '_pipe'? [-Wimplicit-function-declaration]
return pipe (p);
^~~~
_pipe
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'pex_unix_fdopenw':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:811:18: error: 'F_SETFD' undeclared (first use in this function)
if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
^~~~~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:811:27: error: 'FD_CLOEXEC' undeclared (first use in this function); did you mean 'S_IEXEC'?
if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0)
^~~~~~~~~~
S_IEXEC
../../../source/gcc-11.2.0/libiberty/pex-unix.c: In function 'pex_unix_cleanup':
../../../source/gcc-11.2.0/libiberty/pex-unix.c:822:27: warning: identifier 'this' conflicts with C++ keyword [-Wc++-compat]
struct status_list *this;
^~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:825:7: warning: identifier 'this' conflicts with C++ keyword [-Wc++-compat]
this = (struct status_list *) obj->sysdep;
^~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:826:14: warning: identifier 'this' conflicts with C++ keyword [-Wc++-compat]
next = this->next;
^~~~
../../../source/gcc-11.2.0/libiberty/pex-unix.c:827:13: warning: identifier 'this' conflicts with C++ keyword [-Wc++-compat]
free (this);
^~~~
make[3]: *** [Makefile:1140: pex-unix.o] Error 1
make[3]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64/libiberty'
make[2]: *** [Makefile:15776: all-stage1-libiberty] Error 2
make[2]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64'
make[1]: *** [Makefile:27004: stage1-bubble] Error 2
make[1]: Leaving directory '/c/Programming/GNU/GCC/GCC_11.2.0/builds/gcc-x86_64'
make: *** [Makefile:27432: bootstrap-lean] Error 2
所以我的问题是:
1.我应该为 --host 和 --target 指定什么样的目标三元组?我试过gcc -dumpmachine
which 给x86_64-w64-mingw32
. 将这些值分配给 --host 和 --target 只是回到第一个问题。
2.构建目标三元组是否正确,知道脚本在 msys bash 窗口中运行?
3.如果以上方法都不能解决这个编译错误,我该怎么办?
我为(可能)不太清楚的问题道歉,这里已经很晚了,我在这个领域一点经验都没有。如果您需要更多规格,请告诉我。
预先感谢您的帮助。