2016-08-20 63 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

相關問題