Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

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

Description

@gwisp2

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions