gpt4 book ai didi

c - 共享对象链接和 Fpic 的问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:04 25 4
gpt4 key购买 nike

我正在为一个类编写一些 C 代码,但我遇到了需要在 make 文件中完成的编译器问题,当它运行时它总是给出错误

usr/bin/ld: main.o: 重定位 R_X86_64_32S 对符号“被积函数”不能在创建共享对象时使用;使用 -fPIC 重新编译
/usr/bin/ld: integration.o: 创建共享对象时不能使用针对“.rodata”的重定位 R_X86_64_32S;重新编译 -fPIC

我曾尝试以多种方式更改 makefile 以修复 linux 系统上的此错误,但仍然无济于事。

all: main.o integration.o libintegration.so
gcc -fPIC main.o integration.o libintegration.so -o target_bin
libintegration.so: main.o integration.o
gcc main.o integration.o -shared -o libintegration.so
main.o: main.c integration.h
gcc -I . -c main.c
integration.o: integration.c integration.h
gcc -I . -c integration.c
clean:
rm -rf *.o *.so
rm target_bin

感谢您提供的任何帮助

最佳答案

用fpic编译main.c和integration.c。

关于c - 共享对象链接和 Fpic 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52824821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com