【问题标题】:MSYS2 MinGW64 to build GMP/MPFR on Windows as static library, and link them in MSVC project compiled with CLMSYS2 MinGW64 在 Windows 上构建 GMP/MPFR 作为静态库,并将它们链接到使用 CL 编译的 MSVC 项目中
【发布时间】:2020-09-19 22:11:39
【问题描述】:

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

为了从源代码构建 GMP/MPFR,我使用了 mingw-w64-x86_64-toolchain 在 MSYS2 shell 中通过命令 pacman -S mingw-w64-x86_64-toolchain 安装。然后,在 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 链接了,但现在我被卡住了。有什么建议吗?

【问题讨论】:

  • 您可能想检查一下vcpkg 是否支持这些库,并使用它来生成与 Visual Studio 兼容的二进制文件。
  • 好吧,有人说你可以在 Visual Studio 中链接到 .a 库:stackoverflow.com/questions/2096519/…
  • 好的vcpkg是个好主意,我去看看。
  • 我必须查看您的链接。我知道有一些方法可以使用 c 编译的 mingw 静态库,但是 c++ 编译的库不起作用。
  • 那么,GMP可以在Visual Studio中与MS编译器一起使用吗?是否有任何 GMP 静态库可以扔给链接器并正常工作?

标签: c++ visual-studio gmp msys2 mpfr


【解决方案1】:

___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 代表未定义符号)。您还可以调用 GCC 并显示详细信息以查看幕后的确切链接器命令,或调用 gcc -dumpspecs 以准确读取链接的确切时间。

【讨论】:

    猜你喜欢
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多