我运行的是Debian 8和Cython的打包安装(apt-get install Cython)
我正在用CGAL (www.cgal.org)编译我的.pyx文件,但返回错误:
import pyximport; pyximport.install()
from spaces import spaces_rectangle
importterror: Building module spaces failed: [' importterror:/home/scootie/.pyxbld/lib.linux - x86_64 2.7/空间。所以:未定义符号:__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库。链接到所有外部库的正确方法是什么?
解决方案:
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库到*。但解决方案在于将-DCGAL_ROOT放在"-std=c++11"之后。
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