First usage, not compiling

Sisyphus sisyphus1 at optusnet.com.au
Wed Feb 1 06:51:32 CET 2006


----- Original Message ----- 
From: "Drew Roberts" <atroberts at gmail.com>
To: <gmp-discuss at swox.com>
Sent: Wednesday, February 01, 2006 3:50 AM
Subject: First usage, not compiling


> Hi, new to the library.
>
> Ive run the build etc now trying to use and i get the following errors
> on compiling.
>
> andrew-roberts-powerbook-g4-15:~ andrewroberts$ gcc gmpTest.c -lgmp -o
gmpTest
> gmpTest.c: In function 'main':
> gmpTest.c:24: warning: passing argument 1 of '__gmpq_add' from
> incompatible pointer type
> gmpTest.c:24: warning: passing argument 2 of '__gmpq_add' from
> incompatible pointer type
> gmpTest.c:24: warning: passing argument 3 of '__gmpq_add' from
> incompatible pointer type
> /usr/bin/ld: can't locate file for: -lgmp
> collect2: ld returned 1 exit status
>
> from this code
>
>
> #include <stdio.h>
> #include <stdlib.h>
> #include "gmp.h"
>
>
> int main(void){
>
> mpz_t sum, sum2, sum3;
>
> mpz_init(sum);
> mpz_init(sum2);
> mpz_init(sum3);
>
>
> mpq_add(sum3, sum, sum2);
>
> printf("%d", sum);
>
> }
>

This happens because you're passing mpz_t types to the mpq_add() function.
That's not going to work - the mpq_add() function takes only mpq_t types as
its arguments.

Also printf() won't work the way (I assume) you want it to. One solution is
to use gmp_printf(). Here's a script that should compile and run ok:

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

int main(void){

mpz_t sum, sum2, sum3;

mpz_init(sum);
mpz_init_set_ui(sum2, 15);
mpz_init_set_ui(sum3, 101);


mpz_add(sum, sum2, sum3);

gmp_printf("%Zd", sum);

}

Cheers,
Rob



More information about the gmp-discuss mailing list