Generate shared library using cython

Recently, I was trying to configure my neovim. I use coc plugin to do golang code auto-completion work and youcompleteme plugin to do c liked code auto-completion.

I need to add my headers to youcompleteme, however, the loading progress is taking too much time due to the performance limitation of python. Here are two solutions, the first one is porting the python code to c. the second one is let cython do the dirty work for me.

My code is super simple

Use the following cython command to generate c code

cython vobs_include.pyx --embed

Compile the c code to shared library using gcc

gcc -shared -o vobs_include.c -I/usr/local/Frameworks/Python.framework/Versions/3.8/include/python3.8 -L/usr/local/Frameworks/Python.framework/Versions/3.8/lib -lpython3.8 -lpthread -lm -lutil -ldl

Let’s make a python package.

I create a directory called vobs_include and an empty file. In Python language, the plays vita role in package. You can’t import function unless you have an file on the directory. The package looks like the following image.

Importing the function globally and extend the flags list on then restart the ycmd server