pyximport与cgal构建错误:未定义的符号“__gmpq_equal”

时间:2016-08-20 23:19:05

标签: python linux cython cgal

我正在使用Cython的打包安装运行Debian 8(apt-get install cython)。

我正在使用CGAL(www.cgal.org)编译我的.pyx文件,但是返回错误:

import pyximport; pyximport.install()
from spaces import spaces_rectangle
  

ImportError:构建模块空间失败:['ImportError:   /home/scootie/.pyxbld/lib.linux-x86_64-2.7/spaces.so:未定义的符号:   __gmpq_equal \ N']

包含以下文件:

spaces.pyx

from libcpp.vector cimport vector

cdef extern from "cgal_spaces.hpp":
    cdef vector[vector[vector[double]]] wrap_spaces(vector[vector[double]])

def spaces_rectangle(vector[vector[double]] rect):
    return wrap_spaces(rect)

spaces.pyxbld:

def make_ext(modname, pyxfilename):
    from distutils.extension import Extension
    return Extension(name=modname,
                     sources=[pyxfilename],
                     include_dirs=['.'],
                     libraries=['CGAL'],
                     language='c++',
                     extra_compile_args=['-std=c++11'])

和cgal_spaces.hpp:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Partition_traits_2.h>
#include <CGAL/Partition_is_valid_traits_2.h>
#include <CGAL/polygon_function_objects.h>
#include <CGAL/partition_2.h>
#include <cassert>
#include <list>
#include <vector>
{
    *CODE HERE*
}

我是不正确地连接还是遗漏了一些明显的东西?

编辑: 如果我在pyximport之外编译脚本,它编译没有问题。

cython -a spaces.pyx
g++ -std=c++11 -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.7 -o spaces.so spaces.c

似乎pyximport与gmp库存在链接错误。链接到所有外部库的正确方法是什么?

2 个答案:

答案 0 :(得分:1)

解决方案:

def make_ext(modname, pyxfilename):
    from distutils.extension import Extension
    return Extension(name=modname,
                 sources=[pyxfilename],
                 include_dirs=['.'],
                 libraries=['CGAL','gmp'],
                 language='c++',
         extra_compile_args=['-std=c++11','-DCGAL_ROOT="/path/to/CGAL-4.8.1"'])

我已将gmp库添加到* .pyxbld,但解决方案是将-DCGAL_ROOT放在“-std = c ++ 11”之后。

答案 1 :(得分:0)

库中可能缺少gmp库,

strings -f /usr/lib/x86_64-linux-gnu/*.a |grep gmpq_equal

输出

/usr/lib/x86_64-linux-gnu/libgmp.a: __gmpq_equal
/usr/lib/x86_64-linux-gnu/libgmp.a: __gmpq_equal