分页: 1 / 1

makefile文件make后报错

发表于 : 2023-07-10 13:43
fallow
原makefile文件代码如下:
CC = gcc -Os -fopenmp
CFLAGS = -L/usr/local/sac/lib -lsac -lsacio -lm
BIN = ../bin

FDTCC: FDTCC.o sacio.o
${CC} -o ${BIN}/$@ $^ ${CFLAGS}
clean:
rm -f *.o
运行make后报错:
gcc -Os -fopenmp -o ../bin/FDTCC FDTCC.o sacio.o -L/usr/local/sac/lib -lsac -lsacio -lm
/usr/bin/ld: /usr/local/sac/lib/libsac.a(xapiir.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:9:FDTCC] 错误 1

Re: makefile文件make后报错

发表于 : 2023-07-10 16:51
astolia
fallow 写了: 2023-07-10 13:43 /usr/bin/ld: /usr/local/sac/lib/libsac.a(xapiir.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIE
你要链接的libsac.a没用-fPIE参数编译的,而系统上的gcc默认使用-fPIE模式,这两者生成的obj文件不兼容
要么用-fPIE参数重新编译sac的库,要么你加上-fPIC参数让gcc用PIC模式编译

Re: makefile文件make后报错

发表于 : 2023-07-10 17:51
fallow
感谢回复。
由于SAC库没有源码。我选用加上-fPIC,但它仍然报错。
gcc -Os -fopenmp -fPIC -o ../bin/FDTCC FDTCC.o sacio.o -L/usr/local/sac/lib -lsac -lsacio -lm
/usr/bin/ld: /usr/local/sac/lib/libsac.a(xapiir.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:9:FDTCC] 错误 1

Re: makefile文件make后报错

发表于 : 2023-07-10 17:56
astolia
那你加-fno-pie和-no-pie试试

发表于 : 2023-07-10 18:42
fallow
感谢版主,问题解决了。