makefile文件make后报错

其它类软件,非上述版软件
回复
fallow
帖子: 3
注册时间: 2023-07-10 13:36
系统: Ubuntu22.04.2

makefile文件make后报错

#1

帖子 fallow » 2023-07-10 13:43

原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
头像
astolia
论坛版主
帖子: 6454
注册时间: 2008-09-18 13:11

Re: makefile文件make后报错

#2

帖子 astolia » 2023-07-10 16:51

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模式编译
fallow
帖子: 3
注册时间: 2023-07-10 13:36
系统: Ubuntu22.04.2

Re: makefile文件make后报错

#3

帖子 fallow » 2023-07-10 17:51

感谢回复。
由于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
头像
astolia
论坛版主
帖子: 6454
注册时间: 2008-09-18 13:11

Re: makefile文件make后报错

#4

帖子 astolia » 2023-07-10 17:56

那你加-fno-pie和-no-pie试试
fallow
帖子: 3
注册时间: 2023-07-10 13:36
系统: Ubuntu22.04.2

#5

帖子 fallow » 2023-07-10 18:42

感谢版主,问题解决了。
回复