SHARED jsoncpp ERRER
Describe the bug I want to use SHAERD add_library to link my code file.
This is my code
add_library(${PROJECT_NAME} SHARED settingParser.cpp settingParser.h)
target_link_libraries(${PROJECT_NAME} "-Wl,--whole-archive" jsoncpp "-Wl,--no-whole-archive" "-fPIC")
ERROR is :
/usr/bin/ld: /home/github/wd/littletools/3rdparty/lib/json/libjsoncpp.a(json_value.cpp.o): warning: relocation against _ZN4Json10LogicErrorD1Ev' in read-only section .text.unlikely'
/usr/bin/ld: /home/github/wd/littletools/3rdparty/lib/json/libjsoncpp.a(json_reader.cpp.o): relocation R_X86_64_PC32 against symbol _ZTVN4Json17CharReaderBuilderE' 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
gmake[3]: *** [settingParser/CMakeFiles/settingParser.dir/build.make:103: lib/libsettingParser.so] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:439: settingParser/CMakeFiles/settingParser.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:256: CMakeFiles/trimule.dir/rule] Error 2
gmake: *** [Makefile:137: trimule] Error 2
But when I donot use SHARED ,It works success;
add_library(${PROJECT_NAME} settingParser.cpp settingParser.h)
target_link_libraries(${PROJECT_NAME} "-Wl,--whole-archive" jsoncpp "-Wl,--no-whole-archive" "-fPIC")