Search code examples
ccygwinundefined-reference

undefined reference,gmp lib


I installed the gmp libraries in cygwin via its installer. I tried to compile a simple program with gcc.

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


int
main(void)
{
    mpz_t test;
    int i;

    printf("enter number\n");
    gmp_scanf("%Z",&test);
    gmp_printf("test=%Z",test);
    i=mpz_probab_prime_p(test,5);
    if(i)
        printf("prime\n");
    else
        printf("not prime\n");
    return 0;
}

But I got this:

 /cygdrive/c/Users/xxxxx/Documents/NetBeansProjects/rsa_system/main.c:13: undefined reference to  `__imp____gmp_scanf'

This is the first time that I try to use a non-standard library and I'm getting confused here. My compiler is set to Cygwin and I've done all the installation part. Any ideas on what may be wrong? Thank you.


Solution

  • Are you asking gcc to link GMP?

    i.e.: gcc -lgmp main.c ....