将PCL链接到Cython C ++模块
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将PCL链接到Cython C ++模块相关的知识,希望对你有一定的参考价值。
我正在为使用python编写的模拟器开发实时激光雷达数据处理器。由于数据量巨大,因此我[确实]需要c / c ++性能。因此,我发现了Cython,它看起来令人难以置信,除了它不能在编译时包含pcl库这一事实。[因此,我想到要建立.so文件,自行链接pcl,然后在Python包装器中调用该库,但仍然没有结果。这是我的setup.py和我的.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
错误日志(调用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.
我正在为使用python编写的模拟器开发实时激光雷达数据处理器。由于数据量巨大,因此我确实需要c / c ++性能。所以我找到了Cython,它看起来令人难以置信,除了...
distutils.cfg
?您可以将目录pcl/io/
添加到[build_ext]部分中的文件以上是关于将PCL链接到Cython C ++模块的主要内容,如果未能解决你的问题,请参考以下文章
如何设置基本的 C++/C 编译,然后为 emscripten 构建链接脚本
将 DKM 项目链接到内核映像(VIP)项目作为 VxWorks Workbench4 中的子项目/额外模块