yaml-cpp
yaml-cpp copied to clipboard
Link error
When linking against yaml-cpp I got following error:
/usr/bin/ld: /home/beda/.local/lib/../lib/libyaml-cpp.a(convert.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTIN4YAML11InvalidNodeE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
Adding -fPIC
option to yaml-cpp CMakeLists.txt
and reinstalling it solved the problem.
Hi! I have the same error. Have you solved this?
Yes. But I don't remember the exact details.
I cloned the yaml-cpp
repo, added the -fPIC
option somewhere to the CMakeLists
(I guess line 174) and recompiled and reinstalled yaml-cpp
(with cmake ... && make && make install
).
I think you can also use the environment variables CFLAGS
and CXXFLAGS
to fix the issue:
env CFLAGS='-fPIC' CXXFLAGS='-fPIC' cmake -DCMAKE_BUILD_TYPE=Release ..
.
Thank you! I change add_library(yaml-cpp ${library_sources}) to add_library(yaml-cpp SHARED ${library_sources}). And it works , too.
Yes. But I don't remember the exact details. I cloned the
yaml-cpp
repo, added the-fPIC
option somewhere to theCMakeLists
(I guess line 174) and recompiled and reinstalledyaml-cpp
(withcmake ... && make && make install
).
Thank You, I solve that.
env CFLAGS='-fPIC' CXXFLAGS='-fPIC'
hi, Could you please advise where to add the env variable? many thanks!
hi, Could you please advise where to add the env variable? many thanks!
You need to set the environment variables before you create the build system. On macOS and Linux the following commands should work:
git clone https://github.com/jbeder/yaml-cpp.git
cd yaml-cpp
env CFLAGS='-fPIC' CXXFLAGS='-fPIC' cmake -DCMAKE_BUILD_TYPE=Release -Bbuild
cmake --build build -v