collect2:错误:ld 在制作带有代码块的 .so 文件(64 位版本)时返回 1 个退出状态

collect2: error: ld returned 1 exit status on making .so file with codeblocks (64 bit version)

本文关键字:版本 状态 退出 返回 so ld 错误 作带 collect2 代码 文件      更新时间:2023-10-16

我的问题是在代码块中制作.so文件,在旧版本(32位)中制作我的.so文件的项目失败,新版本(64位)中出现以下错误

/usr/bin/ld: obj/Debug/src/tester.o: relocation R_X86_64_PC32 against symbol `_ZTV6tester' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

代码块命令行

g++ -Wall -fexceptions -g -Iinclude -c /home/amini/codes/testr/main.cpp -o obj/Debug/main.o
g++ -Wall -fexceptions -g -Iinclude -c /home/amini/codes/testr/src/tester.cpp -o obj/Debug/src/tester.o
g++ -shared  obj/Debug/main.o obj/Debug/src/tester.o  -o bin/Debug/liblibTestso.so -m64 -fPIC 

帮我解决这个问题,非常感谢

我看到很多关于此错误的链接,没有人清楚地回答我的问题当您从 32 位迁移到 64 位 Linux 系统代码块时,会出现上述错误

通过将 -fPIC 添加到编译器选项,问题无法解决,因为其他对象文件不使用该选项,那么您应该转到设置>编译器>其他设置>高级选项并在那里添加 -fPIC