简体   繁体   English

将 PCL 链接到 Cython C++ 模块

[英]Linking PCL to Cython C++ module

I'm working on a real-time lidar data processer for a simulator written in python.我正在为用 python 编写的模拟器开发实时激光雷达数据处理器。 Since the amount of data is huge I really need c/c++ performances.由于数据量巨大,我真的需要 c/c++ 性能。 So I found Cython and it looked incredible, except for the fact that it cannot include the pcl library at compile time.所以我找到了 Cython,它看起来不可思议,除了它在编译时不能包含 pcl 库。

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.所以我想建立我的.so文件,自己链接pcl,然后在Python包装器中调用库,但仍然没有结果。 Here are my setup.py and my .pyx这是我的 setup.py 和我的 .pyx

Setup.py:安装程序.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: 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):错误日志(调用 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.

Are you using the file distutils.cfg ?你在使用文件distutils.cfg吗? You could add the directory pcl/io/ to the file under the [build_ext] section您可以将目录pcl/io/添加到 [build_ext] 部分下的文件中

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

or modify build_ext in setup.py, eg或修改 setup.py 中的build_ext ,例如

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 .或者将该标题所在的文件夹添加到列表Extensions / include_dirs

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM