我運行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