如何在 linux 上安装 mingw 并将其配置为编译面向 Windows 的 C++ 代码?

问题描述

我想安装 mingw 以使用它的交叉编译器在 Linux(Centos 7)中编译 C++ 代码并获得一个 exe 以在 Windows(64 位)上运行。

但是我无法访问 sudo 并且我无法使用包管理器安装任何东西,所以我必须在某个目录中手动安装它。我从 https://sourceforge.net/projects/mingw-w64/ 下载了 .zip 文件,将其解压缩,并在它的文件夹中尝试使用配置脚本进行设置。通过在解压缩到的文件夹中执行以下操作。

configure --prefix=/home/myUsername/mingw --enable-lib32 --enable-lib64 --enable-experimental --host=x86_64-w64-mingw32

这给了我以下输出错误

checking whether to enable maintainer-specific portions of Makefiles... no
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for x86_64-w64-mingw32-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... x86_64-unkNown-linux-gnu
checking host system type... x86_64-w64-mingw32
checking whether to build the headers... yes
checking whether to build the crt... yes
checking whether to build the optional libraries... no
checking whether to build the optional tools... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
=== configuring in mingw-w64-headers (/home/myUsername/mingw/mingw-w64-v8.0.0/mingw-w64-headers)
configure: running /bin/sh ./configure --disable-option-checking '--prefix=/home/myUsername/mingw'  '--enable-lib32' '--enable-lib64' '--enable-experimental' '--host=x86_64-w64-mingw32' 'host_alias=x86_64-w64-mingw32' --cache-file=/dev/null --srcdir=.
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for x86_64-w64-mingw32-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-w64-mingw32
checking for a sed that does not truncate output... /bin/sed
checking whether to rebuild headers with widl... no
checking whether to build a w32api package for Cygwin... no
checking for c-runtime headers... yes
checking for optional sdk headers... ddk
checking if installing idl files is enabled... no
checking default _WIN32_WINNT version... 0x502
checking default msvcrt... msvcrt (0x700)
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating crt/_mingw.h
config.status: creating config.h
config.status: config.h is unchanged
=== configuring in mingw-w64-crt (/home/myUsername/mingw/mingw-w64-v8.0.0/mingw-w64-crt)
configure: running /bin/sh ./configure --disable-option-checking '--prefix=/home/myUsername/mingw'  '--enable-lib32' '--enable-lib64' '--enable-experimental' '--host=x86_64-w64-mingw32' 'host_alias=x86_64-w64-mingw32' --cache-file=/dev/null --srcdir=.
checking for a BSD-compatible install... /bin/install -c
checking whether build environment is sane... yes
checking for x86_64-w64-mingw32-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-w64-mingw32
checking for sysroot... /home/myUsername/mingw
checking for a sed that does not truncate output... /bin/sed
checking for gawk... (cached) gawk
checking for x86_64-w64-mingw32-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
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 whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking for x86_64-w64-mingw32-g++... no
checking for x86_64-w64-mingw32-c++... no
checking for x86_64-w64-mingw32-gpp... no
checking for x86_64-w64-mingw32-aCC... no
checking for x86_64-w64-mingw32-CC... no
checking for x86_64-w64-mingw32-cxx... no
checking for x86_64-w64-mingw32-cc++... no
checking for x86_64-w64-mingw32-cl.exe... no
checking for x86_64-w64-mingw32-FCC... no
checking for x86_64-w64-mingw32-KCC... no
checking for x86_64-w64-mingw32-RCC... no
checking for x86_64-w64-mingw32-xlC_r... no
checking for x86_64-w64-mingw32-xlC... no
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking how to run the C preprocessor... gcc -E
checking for x86_64-w64-mingw32-ranlib... no
checking for ranlib... ranlib
checking for x86_64-w64-mingw32-dlltool... no
checking for dlltool... no
checking for x86_64-w64-mingw32-ar... no
checking for x86_64-w64-mingw32-lib... no
checking for x86_64-w64-mingw32-link... no
checking for ar... ar
checking the archiver (ar) interface... ar
checking dependency style of gcc... gcc3
checking for x86_64-w64-mingw32-as... no
checking for as... as
checking whether to build a w32api package for Cygwin... no
checking whether to build the Win32 libraries... yes
checking whether to build the Win64 libraries... yes
checking whether to build the WinARM32 libraries... no
checking whether to build the WinARM64 libraries... no
checking whether to use genlib... no
checking whether to enable globbing... no
checking whether to enable private exports... no
checking whether to enable delay import libs... no
checking what to provide as libmsvcrt.a... msvcrt-os
checking whether to enable experimental features... yes
checking whether the compiler supports -municode... no
checking whether the linker provides _CTOR_LIST_... no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking _mingw_mac.h usability... no
checking _mingw_mac.h presence... no
checking for _mingw_mac.h... no
configure: error: Please check if the mingw-w64 header set and the build/host option are set properly.
configure: error: ./configure Failed for mingw-w64-crt

我看到的每个指南或答案都是从使用包管理器 apt-get 安装编译器开始的,所以我有点迷失在哪里看或尝试什么。 提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)