open-source-parsers / open-source-parsers/jsoncpp

SHARED jsoncpp ERRER

Open
#1,411 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug build
Dominant language
C++
Stars
8.9k
Forks
2.7k
Avg merge
31m
Merged PRs (30d)
1

Description

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")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the CMake target using settingParser.cpp and settingParser.h, then inspect the jsoncpp archive and the generated settingParser/CMakeFiles/settingParser.dir/build.make entry. Reproduce the shared-library build and compare it with the working non-SHARED target, focusing on the reported relocation and -fPIC diagnostics. Done means the shared target links successfully without those errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.