Error compiling GMP code in Fedora

270 Views Asked by At

When I try to run the following code in Fedora 26 Cinnamon edition 64 bit:

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


int main(int argc, char * argv[]){

    mpz_t a, b, c;

    mpz_init_set_ui(a,1); /*  a = 1  */
    mpz_init_set_ui(b,1); /*  b = 1  */
    mpz_init(c);

    for (int i=1; i <= 2 ; ++i){
        mpz_add(c,a,b); /* c = a + b */
        mpz_mul_ui(a,b,1);
        mpz_mul_ui(b,c,1);
    }

    mpz_out_str(stdout,10,c);
    printf ("\n");
    mpz_clear(a);
    mpz_clear(b);
    mpz_clear(c);

    return 1;
}

I get the following error message:

fatal error: gmp-x86_64.h: No such file or directory
#include "gmp-x86_64.h"
compilation terminated.

I have got the gmp library installed, when I do whereis gmp I get:

gmp: /usr/include/gmp.h /usr/share/info/gmp.info-1.gz /usr/share/info/gmp.info.gz /usr/share/info/gmp.info-2.gz

And looking for gmp-devel:

When I do dnf install gmp-devel I get:

Last metadata expiration check: 1:48:01 ago on Sun 22 Oct 2017 09:09:57 AM BST.
Package gmp-devel-1:6.1.2-4.fc26.i686 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!

However when I do whereis gmp-devel I only get:

gmp-devel:

Any idea why my system is not recognizing the GMP library?

1

There are 1 best solutions below

2
On BEST ANSWER

Make sure you have gmp-devel installed in your system. It provides the necessary files to compile an application with gmp.

The error you report shows missing header files (*.h) which are typically distributed within -devel (or -dev depending on the distribution).