I'm working on a real-time lidar data processer for a simulator written in python. Since the amount of data is huge I really need c/c++ performances. So I found Cython and it looked incredible, except for the fact that it cannot include the pcl library at compile time.
So I thought to build my .so file, linking pcl on my own, and then call the library in the Python wrapper, but still got no results. Here are my setup.py and my .pyx
Setup.py:
#!/usr/bin/env python
import sys
import os
import shutil
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
setup(cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("multiply",
sources=["cythonBridge.pyx", "Monitor.cpp"],
libraries=["myLib"],
language="c++",
include_dirs=[numpy.get_include()])],
)
cythonBridge.pyx:
#distutils: language = c++
"""
multiply.pyx
simple cython test of accessing a numpy array's data
the C function: c_multiply multiplies all the values in a 2-d array by a scalar, in place.
"""
import cython
# import both numpy and the Cython declarations for numpy
import numpy as np
cimport numpy as np
# declare the interface to the C code
cdef extern void c_multiply (double* array, double value, int m, int n)
@cython.boundscheck(False)
@cython.wraparound(False)
def multiply(np.ndarray[double, ndim=2, mode="c"] input not None, double value):
"""
multiply (arr, value)
Takes a numpy array as input, and multiplies each element by value, in place
param: array -- a 2-d numpy array of np.float64
param: value -- a number that will be multiplied by each element in the array
"""
cdef int m, n
m, n = input.shape[0], input.shape[1]
c_multiply (&input[0,0], value, m, n)
return None
ERROR LOG (when calling python setup.py install):
gcc -pthread -B /home/francesco/anaconda3/envs/carla/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/francesco/anaconda3/envs/carla/lib/python3.6/site-packages/numpy/core/include -I/home/francesco/anaconda3/envs/carla/include/python3.6m -c Monitor.cpp -o build/temp.linux-x86_64-3.6/Monitor.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from Monitor.cpp:13:0:
myLib.h:4:10: fatal error: pcl/io/pcd_io.h: No such file or directory
#include <pcl/io/pcd_io.h>
^~~~~~~~~~~~~~~~~
compilation terminated.