Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libpython error while building YouCompleteMe

I am building YouCompleteMe plugin of vim, following this document. When I run make I get the following error.

Linking CXX shared library /home/sagar/.vim/bundle/YouCompleteMe/python/ycm_core.so
/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status

What is this error?
I have installed pyenv to manage python versions. Is it causing problem?

like image 928
Sagar Rakshe Avatar asked Apr 10 '14 14:04

Sagar Rakshe


2 Answers

Make the linker point to the .so (shared object) file and not the .a (static lib) file.

You can do this specifying the flag when running cmake:

cmake -G "Unix Makefiles" -DPYTHON_LIBRARY=/usr/local/lib/libpython2.7.so . ~/.vim/bundle/YouCompleteme/cpp

Do mind that even though you're using pyenv, YouCompleteMe build may point to an undesired python build as they are not correctly auto-detected right now.

If you're having this problem, you should probably also specify the Python header files correctly:

cmake -G "Unix Makefiles" -DPYTHON_LIBRARY=/usr/local/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR=/usr/local/include/python . ~/.vim/bundle/YouCompleteme/cpp

PS=(I'm assuming your headers are in that path, do check before)

like image 100
Felipe Lema Avatar answered Nov 07 '22 07:11

Felipe Lema


Since some paths were different on my system from the accepted answer (both the CMake and the python lib ones) I'm posting an alternate solution for the above problem:

  1. Make sure to have a shared library version of libpython2.7.so

    $ locate libpython
    /usr/lib/x86_64-linux-gnu/libpython2.7.so.1
    
  2. Either create a symlink to it from where CMake expects it to be

    sudo ln -s "/usr/lib/x86_64-linux-gnu/libpython2.7.so.1" "/usr/lib/libpython2.7.so"
    

    or alternatively, as written in YCM's build script code, you could add additional CMake options to ensure the .so library is properly found

    export EXTRA_CMAKE_ARGS="-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so.1"
    
like image 42
Marco A. Avatar answered Nov 07 '22 07:11

Marco A.