1. Question
When I use Ubuntu18.04 desktop operating system to compile "Onenet Video SDK"(https://github.com/cm-heclouds/video_sdk),I encountered an problem as below:
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(bignum.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(ctr_drbg.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(entropy.c.o): relocation R_X86_64_32 against symbol `mbedtls_platform_entropy_poll' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(entropy_poll.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(rsa.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha1.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha512.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(timing.c.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(aes.c.o): relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(md.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(oid.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(ripemd160.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(sha256.c.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ../../lib/linux/libmbedcrypto.a(md5.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
onvif/libonvif_s.a(stdsoap2.c.o): In function `soap_ssl_init':
stdsoap2.c:(.text+0x68b5): undefined reference to `SSL_library_init'
stdsoap2.c:(.text+0x68ba): undefined reference to `OPENSSL_add_all_algorithms_noconf'
stdsoap2.c:(.text+0x68bf): undefined reference to `SSL_load_error_strings'
onvif/libonvif_s.a(stdsoap2.c.o): In function `ssl_auth_init':
stdsoap2.c:(.text+0x6b54): undefined reference to `SSLv23_method'
onvif/libonvif_s.a(stdsoap2.c.o): In function `tcp_connect':
stdsoap2.c:(.text+0x9612): undefined reference to `SSL_state'
stdsoap2.c:(.text+0x97e3): undefined reference to `sk_pop_free'
stdsoap2.c:(.text+0x9811): undefined reference to `sk_value'
stdsoap2.c:(.text+0x988f): undefined reference to `sk_num'
stdsoap2.c:(.text+0x98b1): undefined reference to `sk_pop_free'
onvif/libonvif_s.a(mecevp.c.o): In function `soap_mec_init':
mecevp.c:(.text+0x76): undefined reference to `EVP_CIPHER_CTX_init'
onvif/libonvif_s.a(mecevp.c.o): In function `soap_mec_cleanup':
mecevp.c:(.text+0x433): undefined reference to `EVP_CIPHER_CTX_cleanup'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_init':
smdevp.c:(.text+0x33d): undefined reference to `HMAC_CTX_init'
smdevp.c:(.text+0x395): undefined reference to `EVP_MD_CTX_init'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_final':
smdevp.c:(.text+0x76a): undefined reference to `HMAC_CTX_cleanup'
smdevp.c:(.text+0x77c): undefined reference to `EVP_MD_CTX_cleanup'
onvif/libonvif_s.a(smdevp.c.o): In function `soap_smd_check':
smdevp.c:(.text+0x844): undefined reference to `HMAC_CTX_cleanup'
smdevp.c:(.text+0x856): undefined reference to `EVP_MD_CTX_cleanup'
/usr/bin/ld: final link failed: Symbol needs debug section which does not exist
collect2: error: ld returned 1 exit status
sample/CMakeFiles/sample_video_s.dir/build.make:373: recipe for target '../bin/sample_video_s' failed
make[2]: *** [../bin/sample_video_s] Error 1
CMakeFiles/Makefile2:225: recipe for target 'sample/CMakeFiles/sample_video_s.dir/all' failed
make[1]: *** [sample/CMakeFiles/sample_video_s.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
2. Analysis:
It is inferred that the trouble should be positioned in linking procedure. The specialize static library "libmbedcrypto.a" was ever compiled without option "fPIC", but the present system compiler turns on this function definitely. So we can see from log that it recommends recompile with -fPIC.
3. Resolution
If we use CMake tool to help compile, we can just add an "-no-pie" to linker flags:
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
Job done.
4. Summarize knowledge
PIE full name is "Position Independent Executable", which is used to create an media between common executable and common shared library. This kind of code can relocate space just as common shared library, and it must be linked to Scrt1.o.
Details can be referred to https://blog.csdn.net/ivan240/article/details/5363395.
————————————————
版权声明:本文为CSDN博主「如月灵」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hanyulongseucas/article/details/87715186
Friday, 21 May 2021
Resolve ‘rodata' can not be used when making a PIE object; recompile with -fPIC?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment