2

I'm working using Visual Studio 2019. I have a project that requires GMP and MPFR ; as far as I know, there are no recent binaries available for Windows and one has to build his own.

To build GMP/MPFR from source code, I used the mingw-w64-x86_64-toolchain installed with the command pacman -S mingw-w64-x86_64-toolchain in MSYS2 shell. Then, from the MinGW64 shell, I just used ./configure, make, make install and ended up with .a libraries, which is, unless I'm wrong, perfectly usable in a VS project.

So now back to my project in Visual Studio, I'm trying to compile it with default compiler CL => it fails with the following errors :

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   

I imagine that I need to link my VS project with a static-library from MSYS2 but I canno't figure which one. Following this topic I already linked with C:\msys64\mingw64\x86_64-w64-mingw32\lib\libmingwex.a but now I'm quite stuck. Any suggestion?

Wassim
  • 386
  • 2
  • 15
  • You may want to check it see if `vcpkg` supports these libraries and use that to generate binaries that are compatible with Visual Studio. – drescherjm Jun 01 '20 at 15:06
  • 1
    Well some people there are saying that you can link with a `.a` library in Visual Studio : https://stackoverflow.com/questions/2096519/from-mingw-static-library-a-to-visual-studio-static-library-lib. – Wassim Jun 01 '20 at 15:10
  • Ok `vcpkg` is a good idea, I'm gonna take a look at it. – Wassim Jun 01 '20 at 15:11
  • I will have to check out your link. I knew there were methods to use `c` compiled mingw static libraries however `c++` compiled libraries don't work. – drescherjm Jun 01 '20 at 15:14
  • So, can GMP be used in Visual Studio with MS compiler? Is there any GMP static library to just throw at linker and just work? – mireazma Mar 13 '21 at 11:25

1 Answers1

2

___chkstk_ms is defined in libgcc (...\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\10.1.0\libgcc.a).

__mingw_raise_matherr is defined in libmingw32 (...\msys64\mingw64\x86_64-w64-mingw32\lib\libmingw32.a).

I don't know if this will help you get a working executable though. :) C++ is out of the question, but it seems you haven't bumped into that particular issue so far.

You can find these symbols using simple substring search and confirm using nm (T stands for a defined symbol, U for an undefined one). You can also call GCC with verbosity turned up to see the exact linker command behind the scenes, or call gcc -dumpspecs to read exactly when is what linked in.

David Macek
  • 868
  • 4
  • 10