Visual Studio 2005 C++ Wrapper unresolved externals

Jeremy Rann xerog1 at gmail.com
Sat Jul 7 16:55:10 CEST 2007


Thanks for the prompt reply. That makes sense - I suppose it would
explain why I wasn't seeing a tutorial on linking the gcc library in
Visual Studio. I may check out the link later - I think for now I'll
just use the C library and go from there. I've been thinking about
benchmarking the various different ways of using the library - static
vs. dynamic, using all mingw vs Visual Studio vs Linux, etc. I may
post that here if I do. Thanks again!

On 7/4/07, Michael Abshoff
<Michael.Abshoff at fsmath.mathematik.uni-dortmund.de> wrote:
> Jeremy Rann wrote:
> > I've been playing around with GMP a bit, but I've run into some
> > difficulty with the C++ wrappers. I'm trying to use GMP in Visual
> > Studio 2005 (Windows, obviously), and the C code works just fine, but
> > when I try to use any C++ code, I get unresolved externals. I think I
> > may have messed up the GMP compile at some point, so here are the
> > steps I took to compile it:
>
> <snip>
>
> > After compiling GMP, I tried to use it within a new project. I added
> > libgmp-3.lib and libgmpxx-3.lib to the linker input by going to
> > "Project->Properties->Configuration Properties->Linker->Input" and
> > adding them to the "Additional Dependencies" section. I compiled and
> > executed a simple hello world app, and then copied libgmp-3.dll and
> > libgmpxx-3.dll to the debug directory so they would be in the app
> > path, and tried to compile the following program:
> >
> > #include <iostream>
> > #include <gmpxx.h>
> > using namespace std;
> >
> > int main (void)
> > {
> >       mpz_class a, b, c;
> >
> >       a = 1234;
> >       b = "-5678";
> >       c = a + b;
> >       cout << "sum is " << c << "\n";
> >       cout << "absolute value is " << abs(c) << "\n";
> >
> >       return 0;
> > }
> >
> > I received the following error:
> >
> > Error 13      error LNK2019: unresolved external symbol
> > "__declspec(dllimport) class std::basic_ostream<char,struct
> > std::char_traits<char> > & __cdecl operator<<(class
> > std::basic_ostream<char,struct std::char_traits<char> > &,struct
> > __mpz_struct const *)"
> > (__imp_??6 at YAAAV?$basic_ostream at DU?$char_traits at D@std@@@std@@AAV01 at PBU__mpz_struct@@@Z)
> > referenced in function "class std::basic_ostream<char,struct
> > std::char_traits<char> > & __cdecl operator<<<struct __mpz_struct
> > [1]>(class std::basic_ostream<char,struct std::char_traits<char> >
> > &,class __gmp_expr<struct __mpz_struct [1],struct __mpz_struct [1]>
> > const &)"
> > (??$?6$$BY00U__mpz_struct@@@@YAAAV?$basic_ostream at DU?$char_traits at D@std@@@std@@AAV01 at ABV?$__gmp_expr@$$BY00U__mpz_struct@@$$BY00U1@@@@Z)      main.obj
> >
> > I tried removing using namespace std and instead using std::cout, but
> > I received the exact same error. What's strange is that I can compile
> > programs with gmp.h using the C commands only, and it works great -
> > even with C++ commands, just not the C++ wrapper for gmp. If I have
> > to, I can stick with C only commands, but the C++ wrapper would be
> > really convenient. Any help would be appreciated - thanks!
>
> Hello Jeremy,
>
> linking C++ code compiled via gcc and the Microsoft toolchain is next to
> impossible due to different name mangling conventions (feel free to
> correct me if you know that I am wrong). In case of the C++ wrapper for
> gmp there is a gmp port for Windows by Brian Gladman. Have a look at
>
>  http://fp.gladman.plus.com/computing/gmp4win.htm
>
> Hope this helps.
>
> Cheers,
>
> Michael
>
>
>


More information about the gmp-discuss mailing list