我有这些简单的源文件:
标头文件
//header.h
#ifndef HEADER_H
#define HEADER_H
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <stdint.h>
#include <string.h>
void test_uint_to_mpz();
#endif
实施档案
//src.c
#include "header.h"
void test_uint_to_mpz() {
char hex_string[200];
uint64_t var;
mpz_t mpz_var;
mpz_init(mpz_var);
printf("Please enter a hex string that fits a variable uint64_t : ");
scanf("%s",hex_string);
var = (uint64_t)strtol(hex_string,NULL,16);
mpz_set_ui(mpz_var,var);
printf("Your input value was: %llx\n",var);
printf("The mpz equivalent is: ");
mpz_out_str(stdout,16,mpz_var);
printf("\n");
mpz_clear(mpz_var);
}
主要
//main.c
#include "header.h"
int main(int argc, char** argv) {
test_uint_to_mpz();
return 0;
}
然后我尝试使用这个简单的行进行编译:
gcc src.c main.c -L/user/lcg/lib -o numericalTest -I./ -lgmp -O3 -static
因为我想使用静态链接。对我来说很好,我很确定gmp的安装很好(参见命令行中的-L选项)。
然而,我有:
gcc src.c main.c -L/user/lcg/lib -o numericalTest -I./ -lgmp -O3 -static
/tmp/ccz2qa8j.o: In function `__gmpz_abs':
main.c:(.text+0x0): multiple definition of `__gmpz_abs'
/tmp/cc0jVOgJ.o:src.c:(.text+0x0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_fits_uint_p':
main.c:(.text+0x20): multiple definition of `__gmpz_fits_uint_p'
/tmp/cc0jVOgJ.o:src.c:(.text+0x20): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_fits_ulong_p':
main.c:(.text+0x60): multiple definition of `__gmpz_fits_ulong_p'
/tmp/cc0jVOgJ.o:src.c:(.text+0x60): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_fits_ushort_p':
main.c:(.text+0x70): multiple definition of `__gmpz_fits_ushort_p'
/tmp/cc0jVOgJ.o:src.c:(.text+0x70): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_get_ui':
main.c:(.text+0xb0): multiple definition of `__gmpz_get_ui'
/tmp/cc0jVOgJ.o:src.c:(.text+0xb0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_getlimbn':
main.c:(.text+0xd0): multiple definition of `__gmpz_getlimbn'
/tmp/cc0jVOgJ.o:src.c:(.text+0xd0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_neg':
main.c:(.text+0x110): multiple definition of `__gmpz_neg'
/tmp/cc0jVOgJ.o:src.c:(.text+0x110): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_perfect_square_p':
main.c:(.text+0x130): multiple definition of `__gmpz_perfect_square_p'
/tmp/cc0jVOgJ.o:src.c:(.text+0x130): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_popcount':
main.c:(.text+0x150): multiple definition of `__gmpz_popcount'
/tmp/cc0jVOgJ.o:src.c:(.text+0x150): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_set_q':
main.c:(.text+0x180): multiple definition of `__gmpz_set_q'
/tmp/cc0jVOgJ.o:src.c:(.text+0x180): first defined here
/tmp/ccz2qa8j.o: In function `__gmpz_size':
main.c:(.text+0x190): multiple definition of `__gmpz_size'
/tmp/cc0jVOgJ.o:src.c:(.text+0x190): first defined here
/tmp/ccz2qa8j.o: In function `__gmpq_abs':
main.c:(.text+0x1a0): multiple definition of `__gmpq_abs'
/tmp/cc0jVOgJ.o:src.c:(.text+0x1a0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpq_neg':
main.c:(.text+0x1c0): multiple definition of `__gmpq_neg'
/tmp/cc0jVOgJ.o:src.c:(.text+0x1c0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpn_add':
main.c:(.text+0x1e0): multiple definition of `__gmpn_add'
/tmp/cc0jVOgJ.o:src.c:(.text+0x1e0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpn_add_1':
main.c:(.text+0x360): multiple definition of `__gmpn_add_1'
/tmp/cc0jVOgJ.o:src.c:(.text+0x360): first defined here
/tmp/ccz2qa8j.o: In function `__gmpn_cmp':
main.c:(.text+0x570): multiple definition of `__gmpn_cmp'
/tmp/cc0jVOgJ.o:src.c:(.text+0x570): first defined here
/tmp/ccz2qa8j.o: In function `__gmpn_sub':
main.c:(.text+0x5a0): multiple definition of `__gmpn_sub'
/tmp/cc0jVOgJ.o:src.c:(.text+0x5a0): first defined here
/tmp/ccz2qa8j.o: In function `__gmpn_sub_1':
main.c:(.text+0x720): multiple definition of `__gmpn_sub_1'
/tmp/cc0jVOgJ.o:src.c:(.text+0x720): first defined here
collect2: error: ld returned 1 exit status
make: *** [output] Error 1
哪里可能是问题?
更新:我发布了makefile
CC=gcc
SRCS=src.c main.c
HEADER=header.h
OBJ_FILES=$(addsuffix ./,(basename $(SRCS)))
INCLUDES=-I./
FLAG=-lgmp -O3
output : $(SRCS) $(HEADER)
$(CC) $(SRCS) -L/user/lcg/lib -o numericalTest $(INCLUDES) $(FLAG) -static
clean :
rm *.o