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

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

我的问题是在 codeblocks 中制作 .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