我运行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库。链接到所有外部库的正确方法是什么?
可能的重复[为什么库的链接顺序有时会导致GCC错误?](http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-是链接,有时因为错误在gcc) –
这就是它!我在主帖中添加了一个额外的编辑来描述解决方案。很容易馅饼,谢谢:) – scootie