Visual Studio 2005 C++ Wrapper unresolved externals

Jeremy Rann xerog1 at gmail.com
Mon Jul 2 20:32:00 CEST 2007


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:

1. downloaded and installed mingw (5.1.3) and msys (1.0.10)

2. downloaded gmp (4.2.1) and unpacked the .bz2 file to
c:\msys\1.0\home\jerann\gmpbuild (obviously, jerann is the username
I'm using for this computer).

3. I had to change /etc/fstab from within msys - apparently, I had
specified my mingw installation directory incorrectly in the initial
install, so I changed c:MinGW to c:/MinGW in fstab

4. I went to the gmp directory in msys and executed "./configure
--disable-static --enable-shared --enable-cxx
--prefix=/home/jerann/gmpcppins/usr/local". I'm not sure why, but it
required that the path I installed to end in /usr/local, so that's
what I did.

5. I executed make, then make check (it passed all tests), then make install

6. I went to the gmp build directory, then to the .libs directory and
renamed libgmp-3.dll.def to libgmp-3.dll-def and libgmpxx-3.dll.def to
libgmpxx-3.dll-def. I did this because I discovered that Visual Studio
will look for libgmp-3.dll.dll otherwise - this appeared to fix the
problem.

7. I opened a Visual Studio command prompt, navigated to the
directory, and executed "lib /machine:i386 /def:libgmp-3.dll-def" and
"lib /machine:i386 /def:libgmpxx-3.dll-def" to generate the
appropriate .lib and .exp files.

8. I copied the .lib and .exp files to
/home/jerann/gmpcppins/usr/local/lib (from within msys)

9. I opened Visual Studio 2005 and added the appropriate directories;
I went to Tools->Options->Projects and Solutions->VC++ Directories,
changed "Show Directories for" to Library files, and added
"c:\msys\1.0\home\jerann\gmpcppins\usr\local\lib", and then changed
"Show Directories For" to "Include Files" and added
"c:\msys\1.0\home\jerann\gmpcppins\usr\local\include".

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!


More information about the gmp-discuss mailing list