编译动态库时遇到relocation R_X86_64_32 against `a local symbol'的错误
编译动态库时遇到如下错误:
I'm Trying to Link a static Library to a shared library , I'm Getting the Following error
/usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(fileappender.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC ../../../libraries/log4cplus/liblog4cplus.a: could not read symbols: Bad value collect2: ld returned 1 exit status
Assuming you are generating a shared library, most probably what happens is that the variant of liblog4cplus.a you are using wasn't compiled with -fPIC. In linux, you can confirm this by extracting the object files from the static library and checking their relocations:
ar -x liblog4cplus.a
readelf --relocs fileappender.o | egrep '(GOT|PLT|JU?MP_SLOT)'
If the output is empty, then the static library is not PIC and cannot be used to generate a shared object.
Since the static library contains object code which was already compiled, providing the -fPIC flag won't help.
You need to get ahold of a version of liblog4cplus.a compiled with -fPIC and use that one instead.
解决动态库编译错误:relocation R_X86_64_32 against `a local symbol'
在编译动态库时遇到`relocation R_X86_64_32 against 'a local symbol'`错误,提示需要使用`-fPIC`参数。问题可能源于编译.o文件或静态库时未添加此参数。解决方案是确保所有编译过程都包含`-fPIC`,以创建符合要求的动态库。
could not read symbols: Bad value&spm=1001.2101.3001.5002&articleId=38688719&d=1&t=3&u=89404d6bffb44892b08052ce794a14ea)

被折叠的 条评论
为什么被折叠?



