GMP and MPFR static linking problem

Joppe Bos jwbos at science.uva.nl
Mon May 31 14:59:37 CEST 2004


L.S.

For about half a year I am working with the GMP and MPFR libraries without 
any problems. Last week I was trying to compile my program (which will be 
an open source factorization library) and link both of the libraries 
static, I get some weird error messages (the code compiles clean if I use 
a shared lib).
I use GMP version 4.1.3 and want to build a version which can run on any 
linux box.

Because I use the computers on my university I must install the lib in the 
/scratch dir. I configured GMP with the following options:
./configure --disable-shared --enable-static 
--build=none-unknown-linux-gnu --enable-mpfr --prefix=/scratch/jwbos/lib

When I want to compile this code (this is just an example when things go 
wrong):

#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>

int main(void)
{
     mpfr_t number1;
     mpz_t number2;
     char *string;
     mp_exp_t end;

     mpfr_init( number1 );
     mpz_init( number2 );

     string = NULL;
     string = mpfr_get_str( NULL, &end, 10, 0, number1, GMP_RNDN );

     if( string == NULL ) { return -1; }
     string[ (int)end ] = '\0';

     mpz_set_str( number2, string, 10 );
     free( string );
     return 0;
}

and I compile with the command:

gcc -o test main.c -static -O2 -I/scratch/jwbos/lib/include 
/scratch/jwbos/lib/lib/libgmp.a /scratch/jwbos/lib/lib/libmpfr.a

I get the following error messages:
/scratch/jwbos/lib/lib/libmpfr.a(get_str.o): In function `mpfr_get_str':
/scratch/jwbos/gmp-4.1.3/mpfr/get_str.c:119: undefined reference to 
`__gmpn_clz_tab'
/scratch/jwbos/gmp-4.1.3/mpfr/get_str.c:322: undefined reference to 
`__gmpz_get_str'
/scratch/jwbos/gmp-4.1.3/mpfr/get_str.c:338: undefined reference to 
`__gmpz_clear'
/scratch/jwbos/lib/lib/libmpfr.a(set_ui.o): In function `mpfr_set_ui':
/scratch/jwbos/gmp-4.1.3/mpfr/set_ui.c:43: undefined reference to 
`__gmpn_clz_tab'
/scratch/jwbos/lib/lib/libmpfr.a(div.o): In function `mpfr_div':
/scratch/jwbos/gmp-4.1.3/mpfr/div.c:160: undefined reference to 
`__gmpn_tdiv_qr'
/scratch/jwbos/gmp-4.1.3/mpfr/div.c:321: undefined reference to 
`__gmpn_clz_tab'
/scratch/jwbos/gmp-4.1.3/mpfr/div.c:172: undefined reference to 
`__gmpn_clz_tab'
/scratch/jwbos/lib/lib/libmpfr.a(mul_ui.o): In function `mpfr_mul_ui':
/scratch/jwbos/gmp-4.1.3/mpfr/mul_ui.c:90: undefined reference to 
`__gmpn_clz_tab'
/scratch/jwbos/lib/lib/libmpfr.a(cmp_ui.o): In function 
`mpfr_cmp_ui_2exp':
/scratch/jwbos/gmp-4.1.3/mpfr/cmp_ui.c:60: undefined reference to 
`__gmpn_clz_tab'
/scratch/jwbos/lib/lib/libmpfr.a(cmp_ui.o): In function 
`mpfr_cmp_si_2exp':
/scratch/jwbos/gmp-4.1.3/mpfr/cmp_ui.c:108: undefined reference to 
`__gmpn_clz_tab'
collect2: ld returned 1 exit status

Is this a problem with GMP and MPFR or am I doing something wrong with the 
linking / compiling?
I have looked in the archives for an answer but wasn't able to find 
anything, if this is asked before I apologize.

Thanks in advance for any reactions, greeting, 

J. Bos






More information about the gmp-discuss mailing list