how to compile cython code
<p>I want to compile my code. I want to write my own cpp file that calls functions from other libraries.</p>

<p>my cpp code</p>

<pre><code>//my_vl.h
int my_vl_k(int normalized_feat_set, int k){}
</code></pre>

<p>my pxd file</p>

<pre><code>#my_vl.pxd
import libc.stdlib

cdef extern from "my_vl.h":
    int my_vl_k(int normalized_feat_set, int k)
</code></pre>

<p>I know I won't need the .h file and the .pxd file for now but it's good practice, and if you can help me on how to include that would really help as well.</p>

<p>my cpp file:</p>

<pre><code>//my_vl.cpp    
extern "C" {
  #include &lt;vl/random.h&gt;
  #include &lt;vl/generic.h&gt;
  #include &lt;vl/kmeans.h&gt;
  #include &lt;vl/mathop.h&gt;
}

#include &lt;cstdlib&gt;
#include &lt;stdio.h&gt;


int my_vl_k(int normalized_feat_set, int K){
  int r = 5;
return r;
}
</code></pre>

<p>my pyx file:</p>

<pre><code>#my_vl.pyx
cimport my_vl


cdef extern from "my_vl.cpp":
    int my_vl_k(int, int)
</code></pre>

<p>my setup file:</p>

<pre><code>#setup.my_val.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext


sourcefiles = ['my_vl.pyx', 'my_vl.cpp']
ext_modules = [Extension("my_vl", 
                          sourcefiles,
                          include_dirs = ['/path/to/vlfeat-0.9.20'],
                           libraries = ['vl'],
                          library_dirs = ['/path/to/vlfeat-0.9.20/bin/glnxa64/']
                          )]

setup(
  name = 'my_val app',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)
</code></pre>

<p>error I get is:</p>

<pre><code>python setup.my_val.py build_ext --inplace
running build_ext
skipping 'my_vl.c' Cython extension (up-to-date)
building 'my_vl' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/path/to/vlfeat-0.9.20 -I/usr/include/python2.7 -c my_vl.cpp -o build/temp.linux-x86_64-2.7/my_vl.o
cc1plus: warning: command line option â-Wstrict-prototypesâ is valid for C/ObjC but not for C++ [enabled by default]
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/path/to/vlfeat-0.9.20 -I/usr/include/python2.7 -c my_vl.cpp -o build/temp.linux-x86_64-2.7/my_vl.o
cc1plus: warning: command line option â-Wstrict-prototypesâ is valid for C/ObjC but not for C++ [enabled by default]
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/my_vl.o build/temp.linux-x86_64-2.7/my_vl.o -L/path/to/vlfeat-0.9.20/bin/glnxa64/ -lvl -o /mnt/disk2/work/visual_clusters/my_vl.so
build/temp.linux-x86_64-2.7/my_vl.o: In function `my_vl_k(int, int)':
/path/to/my_vl.cpp:45: multiple definition of `my_vl_k(int, int)'
build/temp.linux-x86_64-2.7/my_vl.o:/path/to/my_vl.cpp:45: first defined here
collect2: error: ld returned 1 exit status
error: command 'c++' failed with exit status 1
</code></pre>

<p>Not sure what I have to do</p>

<p>You provide the definition of <code>my_vl_k</code> in your header file (<code>{}</code>). Instead write</p>

<pre><code>int my_vl_k(int normalized_feat_set, int k);
</code></pre>

<p>(replace the curly brackets which provide a useless empty definition with a semi-colon which just says that the function exists).</p>

python cython