I have:
my_volume.pxd
cdef float c_cube(float x)
my_volume.pyx
cdef float c_cube(float x):
return x * x * x
my_test.pyx
from my_volume cimport c_cube
def cube(x):
return c_cube(x)
setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
import os
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) + '/'
setup(
name = 'c_optimized',
ext_modules=[
Extension('my_test',
sources=[ROOT_DIR + 'test/my_test.pyx',
ROOT_DIR + 'test/my_volume.pyx',
],
extra_compile_args=["-std=c++11", "-O3"],
include_dirs=[ROOT_DIR],
extra_link_args=["-std=c++11", "-O3"],
language='c++'),
],
cmdclass = {'build_ext': build_ext},
script_args = ['build_ext'],
options = {'build_ext': {'inplace': True, 'force': True}},
)
test_c.py
...
print(cpp.cube(3))
Build errors:
1) multiple definition of PyInit_my_test'
build/temp.linux-x86_64-3.5/home/user/projects/python/service_core/c_optimized/test/my_test.o:/home/user/projects/python/service_core/c_optimized/test/my_test.cpp:783: first defined here
build/temp.linux-x86_64-3.5/home/user/projects/python/service_core/c_optimized/test/my_volume.o: In function
PyInit_my_test':
2) multiple definition of `__pyx_module_is_main_my_test' build/temp.linux-x86_64-3.5/home/user/projects/python/service_core/c_optimized/test/my_test.o:/home/user/projects/python/service_core/c_optimized/test/my_test.cpp:1280: first defined here
What's wrong with my code? I need pxd/pyx common files that I can include to other. How can I include code from one pyx file to another?