kaiseroskilo
kaiseroskilo

Reputation: 1729

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.

Upvotes: 1

Views: 1468

Answers (2)

Mate Soos
Mate Soos

Reputation: 311

Another thing to think about is the order in which you link in GMP libraries. If you link in GMP first, and then GMPXX (i.e. the C++ extension), then you'll be in trouble. Link in GMP first and then GMPXX.

Upvotes: 0

yan
yan

Reputation: 20982

Are you asking gcc to link GMP?

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

Upvotes: 2

Related Questions