2016-08-20 60 views
-1

我运行Debian 8与Cython(apt-get安装cython)的打包安装。pyximport与cgal构建错误:未定义的符号“__gmpq_equal”

我编译与CGAL我.pyx文件(www.cgal.org),但返回错误:

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

ImportError: Building module spaces failed: ['ImportError: /home/scootie/.pyxbld/lib.linux-x86_64-2.7/spaces.so: undefined symbol: __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 

看来有一个链接错误在python的gmp库。链接到所有外部库的正确方法是什么?

+0

可能的重复[为什么库的链接顺序有时会导致GCC错误?](http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-是链接,有时因为错误在gcc) –

+0

这就是它!我在主帖中添加了一个额外的编辑来描述解决方案。很容易馅饼,谢谢:) – scootie

回答

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 
+0

我返回相同的输出提示该库在那里: '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' 我无论是从源并通过易于安装CGAL它在pyximport之外编译得很好。 – scootie

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,但解决方案在于在“-std = C++ 11”之后放置-DCGAL_ROOT。

+0

你基本上重复了我的答案的一部分,“图书馆可能缺少gmp库......”。 '-DCGAL_ROOT =“/ path/to/CGAL-4.8.1”'很奇怪,应该更详细地解释。我怀疑它会影响编译过程。 –

+1

将'gmp'添加到libararies后,它仍然没有编译。它只在我从源代码安装CGAL并链接到已安装的路径后进行编译。另外,这似乎是Debian 8的问题。它在Fedora20上没有任何错误编译。 – scootie

相关问题