python compile error_用Cython返回上双``一个Cython.Compiler.Errors.CompileError`(s.time_since_epoch()计数()。)`...

问题描述: 我想访问的Python C++对象,使用Cython。

当运行python2 setup.py build_ext -i我得到了Cython.Compiler.Errors.CompileError用Cython返回上双``一个Cython.Compiler.Errors.CompileError`(s.time_since_epoch()计数()。)`

你可以有下面一起来看看,并告诉我,我应该怎样改变以获得用Cython编译我的代码?

当我尝试用Cython编译,我得到:

$ python2 setup.py build_ext -i

Compiling ds5.pyx because it changed.

[1/1] Cythonizing ds5.pyx

Error compiling Cython file:

------------------------------------------------------------

...

cdef cppclass os_time_service:

#double get_time() const override

double get_time()

#static_cast(ts.time_since_epoch().count())

double (s.time_since_epoch().count())

^

------------------------------------------------------------

ds5.pyx:15:37: Expected '.', found 'count'

Traceback (most recent call last):

File "setup.py", line 5, in

ext_modules = cythonize("ds5.pyx"))

File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 934, in cythonize

cythonize_one(*args)

File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 1056, in cythonize_one

raise CompileError(None, pyx_file)

Cython.Compiler.Errors.CompileError: ds5.pyx

在h文件中的相关行是:

$ view backend.h

#ifndef LIBREALSENSE_BACKEND_H

#define LIBREALSENSE_BACKEND_H

#include "../include/librealsense/rs.h" // Inherit all type definitions in the public API

#include // For shared_ptr

#include // For function

#include // For this_thread::sleep_for

#include

#include

#include

#include

const uint16_t VID_INTEL_CAMERA = 0x8086;

namespace rsimpl

{

namespace uvc

{

class time_service

{

public:

virtual double get_time() const = 0;

~time_service() = default;

};

class os_time_service: public time_service

{

public:

double get_time() const override

{

auto ts = std::chrono::time_point_cast<:chrono::milliseconds>(std::chrono::system_clock::now());

return static_cast(ts.time_since_epoch().count());

}

};

...

而且我PYX文件是:

$ cat ds5.pyx

# distutils: language = c++

# distutils: sources = uvc-v4l2.cpp

cdef extern from "backend.h" namespace "rsimpl::uvc":

#const uint16_t VID_INTEL_CAMERA = 0x8086

const unsigned short VID_INTEL_CAMERA = 0x8086

cdef cppclass time_service:

#virtual double get_time() const = 0

double get_time()

cdef cppclass os_time_service:

#double get_time() const override

double get_time()

#static_cast(ts.time_since_epoch().count())

double (s.time_since_epoch().count())

cdef class os_time_service_c:

cdef os_time_service *_os_time_service_ptr

def __cinit__(self):

self._os_time_service_ptr = new os_time_service()

if self._os_time_service_ptr == NULL:

raise MemoryError()

def __dealloc__(self):

if self._os_time_service_ptr != NULL:

del self._os_time_service_ptr

cpdef double get_time(self):

return self._os_time_service_ptr.ts.time_since_epoch().count()

环境:

Ubuntu 16.04

Python 2.7.12

Cython 0.25.2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值