yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Link error

Open bedapisl opened this issue 5 years ago • 7 comments

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.

bedapisl avatar Mar 05 '19 10:03 bedapisl

Hi! I have the same error. Have you solved this?

ahandsomeperson avatar May 23 '19 11:05 ahandsomeperson

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

bedapisl avatar May 23 '19 11:05 bedapisl

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 ..

.

sanssecours avatar May 23 '19 11:05 sanssecours

Thank you! I change add_library(yaml-cpp ${library_sources}) to add_library(yaml-cpp SHARED ${library_sources}). And it works , too.

ahandsomeperson avatar May 23 '19 11:05 ahandsomeperson

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

Thank You, I solve that.

HaomingJu avatar Sep 02 '19 07:09 HaomingJu

env CFLAGS='-fPIC' CXXFLAGS='-fPIC' 

hi, Could you please advise where to add the env variable? many thanks!

gregsensem avatar Jan 04 '21 23:01 gregsensem

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

sanssecours avatar Jan 08 '21 16:01 sanssecours