我正在尝试编译一个使用GMP库中许多函数的C程序(gfp2.c)。我使用正常的configure,make和install序列下载并安装了GMP库。我还在安装之前运行了make check并且没有错误。
我正在使用GMP 5.1.1,GCC 4.2.1和MAC OS 10.8.2。
我首先输入gcc gfp2.c -lgmp
来链接库,然后尝试gcc gfp2.c
并在终端上获得以下输出:
1407-wn-172-21-30-223:pqcrypto11_scripts dfish$ gcc gfp2.c -lgmp
v1407-wn-172-21-30-223:pqcrypto11_scripts dfish$ gcc gfp2.c
Undefined symbols for architecture x86_64:
"___gmp_printf", referenced from:
_print_GF in ccrft0vq.o
"___gmp_randinit_default", referenced from:
_setup_GF in ccrft0vq.o
"___gmp_sprintf", referenced from:
_get_GF in ccrft0vq.o
"___gmpz_add", referenced from:
_add_GF in ccrft0vq.o
_mul_GF in ccrft0vq.o
_sqr_GF in ccrft0vq.o
"___gmpz_add_ui", referenced from:
_add_GF_ui in ccrft0vq.o
"___gmpz_addmul", referenced from:
_inv_GF in ccrft0vq.o
"___gmpz_clear", referenced from:
_clear_GF in ccrft0vq.o
_setup_GF in ccrft0vq.o
_free_GF in ccrft0vq.o
"___gmpz_cmp", referenced from:
_cmp_GF in ccrft0vq.o
"___gmpz_cmp_ui", referenced from:
_is_one_GF in ccrft0vq.o
"___gmpz_fdiv_ui", referenced from:
_setup_GF in ccrft0vq.o
"___gmpz_init", referenced from:
_init_GF in ccrft0vq.o
_setup_GF in ccrft0vq.o
"___gmpz_init_set_str", referenced from:
_setup_GF in ccrft0vq.o
"___gmpz_init_set_ui", referenced from:
_setup_GF in ccrft0vq.o
"___gmpz_invert", referenced from:
_inv_GF in ccrft0vq.o
_a24 in ccrft0vq.o
"___gmpz_mod", referenced from:
_add_GF in ccrft0vq.o
_add_GF_ui in ccrft0vq.o
_sub_GF in ccrft0vq.o
_sub_GF_ui in ccrft0vq.o
_scalar_GF in ccrft0vq.o
_scalar_GF_si in ccrft0vq.o
_mul_GF in ccrft0vq.o
...
"___gmpz_mul", referenced from:
_scalar_GF in ccrft0vq.o
_mul_GF in ccrft0vq.o
_sqr_GF in ccrft0vq.o
_inv_GF in ccrft0vq.o
"___gmpz_mul_2exp", referenced from:
_setup_GF in ccrft0vq.o
"___gmpz_mul_si", referenced from:
_scalar_GF_si in ccrft0vq.o
"___gmpz_neg", referenced from:
_inv_GF in ccrft0vq.o
"___gmpz_pow_ui", referenced from:
_setup_GF in ccrft0vq.o
"___gmpz_set", referenced from:
_copy_GF in ccrft0vq.o
_add_GF_ui in ccrft0vq.o
_sub_GF_ui in ccrft0vq.o
_neg_GF in ccrft0vq.o
"___gmpz_set_str", referenced from:
_set_GF in ccrft0vq.o
"___gmpz_set_ui", referenced from:
_shamir in ccrft0vq.o
_a24 in ccrft0vq.o
"___gmpz_sizeinbase", referenced from:
_mont_3ladder in ccrft0vq.o
_shamir in ccrft0vq.o
"___gmpz_sub", referenced from:
_sub_GF in ccrft0vq.o
_neg_GF in ccrft0vq.o
_mul_GF in ccrft0vq.o
_sqr_GF in ccrft0vq.o
"___gmpz_sub_ui", referenced from:
_setup_GF in ccrft0vq.o
_sub_GF_ui in ccrft0vq.o
"___gmpz_tstbit", referenced from:
_mont_3ladder in ccrft0vq.o
_shamir in ccrft0vq.o
"___gmpz_urandomm", referenced from:
_random_GF in ccrft0vq.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我是C编程和使用库等的新手,并且真的不知道我在做什么,所以任何帮助都表示赞赏。谢谢!
答案 0 :(得分:2)
您需要在GMP库中链接:
gcc gfp2.c -lgmp
(目前尚不清楚为什么你最初工作然后在没有图书馆的情况下重新开始工作)。
答案 1 :(得分:1)
您的第一次尝试已完成编译和链接。您不需要执行第二步。如果你检查你的目录,你会发现一个名为a.out的文件,它是你需要的可执行文件。