在 Linux 上使用 Mingw 编译 GMP 库
Compiling GMP Library with Mingw on Linux
我尝试在 Windows 上编译我编写的 C++ 代码 G++ GMP。我的程序在 Ubuntu 上运行良好。我需要使用 Mingw-G++ 重新编译和构建库,最终使用 Mingw 为 Windows.
编译我的最终程序
我现在的问题:
库提供的配置文件看起来不能在任何地方将 Mingw-GCC over GCC 设置为编译器。您可以为构建和主机类型设置标志,但它们不会带来预期的结果(在我的测试中)。
我远不是 makefile 和 shell 脚本方面的专家,所以它可能 看起来 就像我无法设置编译器一样,但我想我只是忽略了一些东西。我可以想象我需要自己在配置文件中设置 Mingw 的路径,但我不想破坏任何东西 YET.
我发现 configure
文件中有一个 CClist,它设置为 gcc
/ gcc icc
等等...它决定了要设置哪个编译器列表在 CPU 构建类型上 (arm/amd64/etc...)。<
另一个问题:linux 上的 mingw gcc 编译器没有像 windows 上那样命名为 gcc,而是 x86_64-w64-mingw32-gcc
...所以脚本无法将其检测为 gcc
提前致谢
编辑
在@SuperStormer 的帮助下,我将编译器正确设置为 mingw32-gcc
,正如我的 config.status
文件所示,但是 make check 失败并显示以下警告:
z.lo spinner.lo trace.lo ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-ar cq .libs/libtests.a memory.o misc.o refmpf.o refmpn.o refmpq.o refmpz.o spinner.o trace.o
libtool: link: x86_64-w64-mingw32-ranlib .libs/libtests.a
libtool: link: ( cd ".libs" && rm -f "libtests.la" && ln -s "../libtests.la" "libtests.la" )
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-bswap.o t-bswap.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-bswap.exe t-bswap.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-bswap.exe t-bswap.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-constants.o t-constants.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-constants.exe t-constants.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-constants.exe t-constants.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-count_zeros.o t-count_zeros.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-count_zeros.exe t-count_zeros.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-count_zeros.exe t-count_zeros.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-hightomask.o t-hightomask.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-hightomask.exe t-hightomask.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-hightomask.exe t-hightomask.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-modlinv.o t-modlinv.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-modlinv.exe t-modlinv.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-modlinv.exe t-modlinv.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-popc.o t-popc.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-popc.exe t-popc.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-popc.exe t-popc.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-parity.o t-parity.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-parity.exe t-parity.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-parity.exe t-parity.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-sub.o t-sub.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-sub.exe t-sub.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-sub.exe t-sub.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
make[4]: Verzeichnis „/home/me/Downloads/gmp-6.2.1/tests“ wird verlassen
还有这个
FAIL: t-bswap.exe
FAIL: t-constants.exe
FAIL: t-count_zeros.exe
FAIL: t-hightomask.exe
FAIL: t-modlinv.exe
FAIL: t-popc.exe
FAIL: t-parity.exe
FAIL: t-sub.exe
============================================================================
Testsuite summary for GNU MP 6.2.1
============================================================================
# TOTAL: 8
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 8
# XPASS: 0
# ERROR: 0
============================================================================
See tests/test-suite.log
测试套件日志说:它不能 运行 .exe 文件。我很清楚为什么不能,但是是否有任何解决方法来创建 linux 可执行文件?或者 make check 预计会失败?
解决方案
快速猜测是使用 mingw 在 linux 上进行检查无法成功。
我 运行 进行安装,我的程序现在 运行 没问题(关于我的库问题)
此答案主要基于此mailing list post。
命令 运行:
export CC=x86_64-w64-mingw32-gcc
export CC_FOR_BUILD=x86_64-linux-gnu-gcc
./configure --build=x86_64-linux-gnu --host=x86_64-w64-mingw32 --enable-cxx
make
随意调整。
我尝试在 Windows 上编译我编写的 C++ 代码 G++ GMP。我的程序在 Ubuntu 上运行良好。我需要使用 Mingw-G++ 重新编译和构建库,最终使用 Mingw 为 Windows.
编译我的最终程序我现在的问题:
库提供的配置文件看起来不能在任何地方将 Mingw-GCC over GCC 设置为编译器。您可以为构建和主机类型设置标志,但它们不会带来预期的结果(在我的测试中)。 我远不是 makefile 和 shell 脚本方面的专家,所以它可能 看起来 就像我无法设置编译器一样,但我想我只是忽略了一些东西。我可以想象我需要自己在配置文件中设置 Mingw 的路径,但我不想破坏任何东西 YET.
我发现 configure
文件中有一个 CClist,它设置为 gcc
/ gcc icc
等等...它决定了要设置哪个编译器列表在 CPU 构建类型上 (arm/amd64/etc...)。<
另一个问题:linux 上的 mingw gcc 编译器没有像 windows 上那样命名为 gcc,而是 x86_64-w64-mingw32-gcc
...所以脚本无法将其检测为 gcc
提前致谢
编辑
在@SuperStormer 的帮助下,我将编译器正确设置为 mingw32-gcc
,正如我的 config.status
文件所示,但是 make check 失败并显示以下警告:
z.lo spinner.lo trace.lo ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-ar cq .libs/libtests.a memory.o misc.o refmpf.o refmpn.o refmpq.o refmpz.o spinner.o trace.o
libtool: link: x86_64-w64-mingw32-ranlib .libs/libtests.a
libtool: link: ( cd ".libs" && rm -f "libtests.la" && ln -s "../libtests.la" "libtests.la" )
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-bswap.o t-bswap.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-bswap.exe t-bswap.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-bswap.exe t-bswap.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-constants.o t-constants.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-constants.exe t-constants.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-constants.exe t-constants.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-count_zeros.o t-count_zeros.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-count_zeros.exe t-count_zeros.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-count_zeros.exe t-count_zeros.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-hightomask.o t-hightomask.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-hightomask.exe t-hightomask.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-hightomask.exe t-hightomask.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-modlinv.o t-modlinv.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-modlinv.exe t-modlinv.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-modlinv.exe t-modlinv.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-popc.o t-popc.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-popc.exe t-popc.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-popc.exe t-popc.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-parity.o t-parity.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-parity.exe t-parity.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-parity.exe t-parity.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I.. -I.. -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -c -o t-sub.o t-sub.c
/bin/bash ../libtool --tag=CC --mode=link x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -no-install -o t-sub.exe t-sub.o libtests.la ../libgmp.la
libtool: warning: '-no-install' is ignored for x86_64-w64-mingw32
libtool: warning: assuming '-no-fast-install' instead
libtool: link: x86_64-w64-mingw32-gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=k8 -march=k8 -o t-sub.exe t-sub.o ./.libs/libtests.a /home/me/Downloads/gmp-6.2.1/.libs/libgmp.a ../.libs/libgmp.a
make[4]: Verzeichnis „/home/me/Downloads/gmp-6.2.1/tests“ wird verlassen
还有这个
FAIL: t-bswap.exe
FAIL: t-constants.exe
FAIL: t-count_zeros.exe
FAIL: t-hightomask.exe
FAIL: t-modlinv.exe
FAIL: t-popc.exe
FAIL: t-parity.exe
FAIL: t-sub.exe
============================================================================
Testsuite summary for GNU MP 6.2.1
============================================================================
# TOTAL: 8
# PASS: 0
# SKIP: 0
# XFAIL: 0
# FAIL: 8
# XPASS: 0
# ERROR: 0
============================================================================
See tests/test-suite.log
测试套件日志说:它不能 运行 .exe 文件。我很清楚为什么不能,但是是否有任何解决方法来创建 linux 可执行文件?或者 make check 预计会失败?
解决方案
快速猜测是使用 mingw 在 linux 上进行检查无法成功。 我 运行 进行安装,我的程序现在 运行 没问题(关于我的库问题)
此答案主要基于此mailing list post。
命令 运行:
export CC=x86_64-w64-mingw32-gcc
export CC_FOR_BUILD=x86_64-linux-gnu-gcc
./configure --build=x86_64-linux-gnu --host=x86_64-w64-mingw32 --enable-cxx
make
随意调整。