I need GMPXX on MinGW. This is driving me nuts.
EDIT: I should mention I've tried using the precompiled MinGW GMP and GMPXX libraries via the mingw-get. And they fail. I removed them.
I compiled GMP in MSYS with the following line.
./configure --enable-cxx --prefix="/mingw" && make && make install && make check
And it comes out perfectly.
Here's my code:
#include <gmpxx.h>
#include <iostream>
mpz_class pascal[101][101];
int main(){
unsigned int i,j;
for(i=0;i<102;i++){
pascal[i][0]=1;
}
for(i=1;i<102;i++){
for(j=1;j<102;j++){
pascal[i][j]=pascal[i-1][j-1]+pascal[i-1][j];
}
}
std::cout<<pascal[100][50];
return 0;
}
Then I try:
$ g++ -v -lgmpxx -lgmp -o Pascal.exe Pascal.cpp
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'Pascal.exe' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/cc1plus.exe -quiet -v -iprefix c:\mingw\bin\../lib/gcc/mingw32/4.6.2/ Pascal.cpp -quiet -dumpbase Pascal.cpp -mtune=i386 -march=i386 -auxbase Pascal -version -o C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccHjg98a.s
GNU C++ (GCC) version 4.6.2 (mingw32)
compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
warning: GMP header version 5.0.1 differs from library version 5.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.2/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/include-fixed"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/../../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include-fixed
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../mingw32/include
End of search list.
GNU C++ (GCC) version 4.6.2 (mingw32)
compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1, MPC version 0.8.1
warning: GMP header version 5.0.1 differs from library version 5.0.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f7eb4168c2cf10318cc29da8d23b7f3c
COLLECT_GCC_OPTIONS='-v' '-o' 'Pascal.exe' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/as.exe -o C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccHjg98a.s
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.2/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'Pascal.exe' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/collect2.exe -Bdynamic -u ___register_frame_info -u ___deregister_frame_info -o Pascal.exe c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtbegin.o -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../.. -L/mingw/lib -lgmpxx -lgmp C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtend.o
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o:Pascal.cpp:(.text$_ZN17__gmp_binary_plus4evalEP12__mpz_structPKS0_S3_[__gmp_binary_plus::eval(__mpz_struct*, __mpz_struct const*, __mpz_struct const*)]+0x1b): undefined reference to `__gmpz_add'
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o:Pascal.cpp:(.text$_ZN10__gmp_exprIA1_12__mpz_structS1_EC1Ev[__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr()]+0xd): undefined reference to `__gmpz_init'
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o:Pascal.cpp:(.text$_ZN10__gmp_exprIA1_12__mpz_structS1_ED1Ev[__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr()]+0xd): undefined reference to `__gmpz_clear'
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o:Pascal.cpp:(.text$_ZN10__gmp_exprIA1_12__mpz_structS1_EaSEi[__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::operator=(int)]+0x14): undefined reference to `__gmpz_set_si'
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccKxmt7C.o:Pascal.cpp:(.text$_ZlsIA1_12__mpz_structERSoS2_RK10__gmp_exprIT_S4_E[std::basic_ostream<char, std::char_traits<char> >& operator<< <__mpz_struct [1]>(std::basic_ostream<char, std::char_traits<char> >&, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&)]+0x1c): undefined reference to `operator<<(std::ostream&, __mpz_struct const*)'
collect2: ld returned 1 exit status
Generally, the undefined reference comes when I forget to link the library. But I didn't. Could be that the header and the libraries aren't matching up.
Here's the (relevant) listing of the folders:
$ ls -l /mingw/lib/*gmp*.*
-rw-r--r-- 1 DMS40 Administrators 731804 May 4 16:32 /mingw/lib/libgmp.a
-rw-r--r-- 1 DMS40 Administrators 859 May 4 16:32 /mingw/lib/libgmp.la
-rw-r--r-- 1 DMS40 Administrators 23532 May 4 16:32 /mingw/lib/libgmpxx.a
-rw-r--r-- 1 DMS40 Administrators 885 May 4 16:32 /mingw/lib/libgmpxx.la
-rw-r--r-- 1 DMS40 Administrators 4498 Mar 25 2011 /mingw/lib/libigmpagnt.a
$ ls -l /mingw/include/*gmp*.*
-rw-r--r-- 1 DMS40 Administrators 86243 May 4 16:32 /mingw/include/gmp.h
-rw-r--r-- 1 DMS40 Administrators 114646 May 4 16:32 /mingw/include/gmpxx.h
These are the right folders.
EDIT: Tried with a straight C approach. No love.
#include <gmp.h>
mpz_t pascal[101][101];
int main(){
unsigned int i,j;
for(i=0;i<102;i++){
for(j=0;j<102;j++){
mpz_init(pascal[i][j]);
}
}
for(i=0;i<102;i++){
mpz_setui(pascal[i][0],1);
}
for(i=1;i<102;i++){
for(j=1;j<102;j++){
mpz_add(pascal[i][j],pascal[i-1][j-1],pascal[i-1][j]);
}
}
return 0;
}
//------------------------------------------------------------------------------------------------------//
$ gcc -lgmp Pascal.c
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccIY5e5q.o:Pascal.c:(.text+0x69): undefined reference to `__gmpz_init'
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccIY5e5q.o:Pascal.c:(.text+0xcb): undefined reference to `mpz_setui'
C:\DOCUME~1\DMS40\LOCALS~1\Temp\ccIY5e5q.o:Pascal.c:(.text+0x1ce): undefined reference to `__gmpz_add'
collect2: ld returned 1 exit status
Help me out, DaniWeb. (EDIT: Pretty) Please? What are the questions I'm not asking?