Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ input/output functions for gmp types are not exported by a dynamic library for Windows #12

Open
gwisp2 opened this issue Feb 12, 2022 · 0 comments

Comments

@gwisp2
Copy link

gwisp2 commented Feb 12, 2022

Context

Some functions (mostly operator<<, and operator>>) are not included in libgmp.def and therefore are not exported by a dynamic library for Windows.

Expected Behavior

The code below should compile and link successfully against gmp built as a dynamic library.

Actual Behavior

The linker can't find some functions. E.g. operator<< defined in osmpq.cc.

main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<cha
r,struct std::char_traits<char> > &,struct __mpq_struct const *)" (__imp_??6@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV01@PEBU__mpq_struct@@@Z) referenced in function "class
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<<struct __mpq_struct [1],struct __mpq_struct [1]>(class std::basic_ostream<char,struct std::char_traits<char> >
 &,class __gmp_expr<struct __mpq_struct [1],struct __mpq_struct [1]> const &)" (??$?6$$BY00U__mpq_struct@@$$BY00U0@@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV01@AEBV?$__gmp_
expr@$$BY00U__mpq_struct@@$$BY00U1@@@@Z) [D:\dev\gmp-test\build\main.vcxproj]
D:\dev\gmp-test\build\Debug\main.exe : fatal error LNK1120: 1 unresolved externals [D:\dev\gmp-test\build\main.vcxproj]

Steps to Reproduce

#include <iostream>
#include <gmpxx.h>

int main() {
  std::cout << mpq_class(1) << std::endl;
  return 0;
}

Possible Fix

Add missing names into libgmp.def. An obstacle is that C++ functions names are mangled with mangling rules dependent on a compiler version. An alternative is to patch sources and add __declspec(dllexport).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant