PHP

Ubuntu下编译PHP报错ld: final link failed: nonrepresentable section on output

具体报错信息如下:
/usr/bin/ld: /data/app/openssl/lib/libcrypto.a(ecs_asn1.o): relocation R_X86_64_PC32 against symbol `ECDSA_SIG_it' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libcrypto.a(cms_lib.o): relocation R_X86_64_PC32 against symbol `CMS_ContentInfo_it' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libcrypto.a(cms_io.o): relocation R_X86_64_PC32 against symbol `CMS_ContentInfo_it' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libcrypto.a(cms_dd.o): relocation R_X86_64_PC32 against symbol `CMS_DigestedData_it' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(s2_srvr.o): relocation R_X86_64_PC32 against symbol `ssl2_accept' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(s2_clnt.o): relocation R_X86_64_PC32 against symbol `ssl2_connect' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(s2_lib.o): relocation R_X86_64_PC32 against symbol `ssl2_ciphers' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(s3_srvr.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(s3_clnt.o): relocation R_X86_64_PC32 against symbol `ssl3_connect' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(s3_lib.o): relocation R_X86_64_PC32 against symbol `ssl3_ciphers' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(t1_enc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(d1_both.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(ssl_lib.o): relocation R_X86_64_PC32 against symbol `ssl_undefined_function' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libssl.a(d1_enc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /data/app/openssl/lib/libcrypto.a(txt_db.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [Makefile:141:libphp5.la] 错误 1
已邀请:

空心菜 - 无分享不快乐 助力技术开源分享 运维一枚

赞同来自:

-fPIC重新编译,这个问题只有在64位系统中编译的时候才会出现。-fPIC 作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),则产生的代码中,没有绝对地址,全部使用相对地址,故而代码可以被加载器加载到内存的任意位置,都可以正确的执行。这正是共享库所要求的,共享库被加载时,在内存的位置不是固定的。
解决方法:
如果是make ,在./configure 前面添加: CFLAGS="-fPIC" 变成:
CFLAGS="-fPIC" ./configure
对于cmake生成的makefile则可以在CMakeList.txt或者cmake生成的CMakeCache.txt中加上-fPIC:
CMAKE_CXX_FLAGS:STRING=-fPIC,CMAKE_C_FLAGS:STRING=-fPIC,CMAKE_EXE_LINKER_FLAGS:STRING=-fPIC
参考:https://blog.csdn.net/jirryzhang/article/details/72784439 

空心菜 - 无分享不快乐 助力技术开源分享 运维一枚

赞同来自:

如果还不行,那就可能就是你openssl编译的时候,需要加上 -fPIC参数:
./configure -fPIC
参考: https://www.jianshu.com/p/c5d8172b3b76  

要回复问题请先登录注册