0

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.
Axer
  • 1

1 Answers1

0

Are you using the file distutils.cfg? You could add the directory pcl/io/ to the file under the [build_ext] section

[build_ext]
include_dirs= path/to/pcl/io/

or modify build_ext in setup.py, e.g.

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension(".\CythonTutorial\src\helloworld", [".\CythonTutorial\src\helloworld.pyx"])]
)

Or add the folder where that header is to the list Extensions / include_dirs.

https://stackoverflow.com/a/29627625/7919597

https://github.com/cython/cython/issues/2771

Joe
  • 6,758
  • 2
  • 26
  • 47
  • Sorry for the delay but i was with no internet till now (weird to say in 2020 uh?) I tried to include pcl directly from its folder but I didn't get the results I expected, but it's possible that I changed some stuff in the project's structure without realizing it. I'll try again in a moment and will let you know – Axer Feb 04 '20 at 13:13