Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link error #682

Open
bedapisl opened this issue Mar 5, 2019 · 7 comments
Open

Link error #682

bedapisl opened this issue Mar 5, 2019 · 7 comments

Comments

@bedapisl
Copy link
Contributor

bedapisl commented Mar 5, 2019

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.

@ahandsomeperson
Copy link

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

@bedapisl
Copy link
Contributor Author

bedapisl commented May 23, 2019

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

@sanssecours
Copy link

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

.

@ahandsomeperson
Copy link

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

@HaomingJu
Copy link

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.

@gregsensem
Copy link

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

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

@sanssecours
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants