c++ - MSYS2 MinGW64 在 Windows 上构建 GMP/MPFR 作为静态库,并将它们链接到用 CL 编译的 MSVC 项目中

标签 c++ visual-studio gmp msys2 mpfr

我正在使用 Visual Studio 2019。我有一个需要 GMP 和 MPFR 的项目;据我所知,最近没有适用于 Windows 的二进制文件,必须构建自己的二进制文件。

为了从源代码构建 GMP/MPFR,我使用了通过命令 pacman -S mingw-w64-x86_64-toolchain 安装的 mingw-w64-x86_64-toolchain在 MSYS2 外壳中。然后,在 MinGW64 shell 中,我只使用了 ./configure, make, make install 并最终得到了 .a 库,除非我错了,否则它在 VS 项目中完全可用。

现在回到 Visual Studio 中的项目,我尝试使用默认编译器 CL 来编译它 => 它失败并出现以下错误:

Severity    Code    Description                                                                             Project     File                                                Line    Suppression State
Error   LNK1120     2 unresolved externals                                                                  MyProject   MyProject.exe                                       1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(aors.o)                                    1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(dcpi1_bdiv_q.o)                            1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(dcpi1_bdiv_qr.o)                           1   
Error   LNK2019     unresolved external symbol ___chkstk_ms referenced in function mpn_dcpi1_divappr_q_n    MyProject   libgmp.a(dcpi1_divappr_q.o)                         1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(dcpi1_div_qr.o)                            1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(divexact.o)                                1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(gcd.o)                                     1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(hgcd_reduce.o)                             1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(invertappr.o)                              1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt103-divexact.o)                          1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt31-mul.o)                                1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt55-cmp.o)                                1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt57-cmp_ui.o)                             1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt64-mul.o)                                1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt82-mul.o)                                1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt97-gcd.o)                                1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(lt99-tdiv_qr.o)                            1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(mullo_n.o)                                 1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(mul_n.o)                                   1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(nussbaumer_mul.o)                          1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(sqr.o)                                     1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(toom42_mul.o)                              1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libgmp.a(toom53_mul.o)                              1   
Error   LNK2019     unresolved external symbol __mingw_raise_matherr referenced in function cos             MyProject   libmingwex.a(lib64_libmingwex_a-cos.o)              1   
Error   LNK2001     unresolved external symbol ___chkstk_ms                                                 MyProject   libmingwex.a(lib64_libmingwex_a-mingw_pformat.o)    1   
Error   LNK2001     unresolved external symbol __mingw_raise_matherr                                        MyProject   libmingwex.a(lib64_libmingwex_a-sin.o)              1   
Error   LNK2001     unresolved external symbol __mingw_raise_matherr                                        MyProject   libmingwex.a(lib64_libmingwex_a-sqrt.o)             1   

我想我需要将我的 VS 项目与 MSYS2 中的静态库链接起来,但我不知道是哪一个。正在关注this topic我已经与 C:\msys64\mingw64\x86_64-w64-mingw32\lib\libmingwex.a 链接,但现在我陷入了困境。有什么建议吗?

最佳答案

___chkstk_ms 在 libgcc (...\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\10.1.0\libgcc.a) 中定义。

__mingw_raise_matherr 在 libmingw32 中定义 (...\msys64\mingw64\x86_64-w64-mingw32\lib\libmingw32.a)。

我不知道这是否会帮助您获得一个有效的可执行文件。 :) C++ 是不可能的,但到目前为止您似乎还没有遇到这个特定问题。

您可以使用简单的子字符串搜索找到这些符号,并使用nm进行确认(T代表已定义的符号,U代表 undefined symbol ) )。您还可以调用 GCC,并调高详细程度来查看幕后的确切链接器命令,或者调用 gcc -dumpspecs 来准确读取链接的时间。

关于c++ - MSYS2 MinGW64 在 Windows 上构建 GMP/MPFR 作为静态库,并将它们链接到用 CL 编译的 MSVC 项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62135116/

相关文章:

c++ - 链接器找不到导入的 DLL 的 LIB 文件

c++ - GMP 错误的朴素素数算法 c++

c++ - 将多个源目录构建到同一个目标目录中

.net - 在多核中运行 Visual Studio

c# - 使用 Visual Studio 的代码模型查找类的更快方法是什么?

division - 如何对大量数字(bignums)实现长除法

c++ - GMP:将整数转换为 std::string

c++ - 此声明在 C++ 中没有存储类或类型说明符

c++ - 使用 boost::filesystem 时如何正确处理错误?

c++ - 如何在 C++ 中将字符串分配给 char *pw