简体   繁体   中英

Connecting 2 libs: can not be used when making a shared object; recompile with -fPIC

I've connected two libraryes.

a) HotStuff https://github.com/hot-stuff/libhotstuff b) Bls (with relic) https://github.com/Chia-Network/bls-signatures

I had to add a lot of bls flags into the hotstuff cmake:

(On root dir level) https://gist.github.com/Raycoms/29e58b80fb493d89d1ea4bfe6f953984

(In examples folder) https://gist.github.com/Raycoms/8e757d0ab0fd61a006db629dbc35e6fc

However, when building this, this results in the following exception:

/usr/bin/ld: _deps/relic-build/lib/librelic_s.a(relic_core.c.o): relocation R_X86_64_TPOFF32 against symbol `core_ctx' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: bls/src/libblstmp.a(elements.cpp.o): warning: relocation against `_ZTVSt9basic_iosIcSt11char_traitsIcEE@@GLIBCXX_3.4' in read-only section `.text._ZN3bls4Util6HexStrB5cxx11ERKSt6vectorIhSaIhEE[_ZN3bls4Util6HexStrB5cxx11ERKSt6vectorIhSaIhEE]'
/usr/bin/ld: bls/src/libblstmp.a(elements.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN3bls4Util19secureAllocCallbackE' 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
make[2]: *** [CMakeFiles/hotstuff_shared.dir/build.make:90: libhotstuff.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:350: CMakeFiles/hotstuff_shared.dir/all] Error 2
make: *** [Makefile:133: all] Error 2

Weirdly, compiling and running it in CLion works just fine, but doing it in the commandline results in the above exception which leaves me confused.

Quick update. It works in CLion because executing "make" in the examples folder works well enough to build the app and app-client starters. However, the overall build doesn't work.

You need to tell cmake that the target producing the librelic_s.a static lib should use position independent code by setting the POSITION_INDEPENDENT_CODE target property:

add_library(relic_s STATIC ...)
set_target_properties(relic_s PRIVATE POSITION_INDEPENDENT_CODE True)

Not sure this can be done without modifying the cmake file of relic...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM