2016-08-20 2 views
-1

私はDebian 8をCythonのパッケージインストール(apt-get install cython)で実行しています。pyximport with cgalビルドエラー:未定義シンボル "__gmpq_equal"

私はCGAL(www.cgal.org)と私の.pyxファイルをコンパイルするが、エラーが返されています:以下のファイルと

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 

pyximportに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 |グレップのgmpq_equal /usr/lib/x86_64-linux-gnu/libgmp.a:__gmpq_equal /usr/lib/x86_64-linux-gnu/libgmp.a: __gmpq_equal'私はソースからとのapt経由の両方のCGALをインストールしましたそれはpyximportの外で細かいコンパイルを行います。 – scootie

1

ソリューション:私は* .pyxbldへの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"']) 

が、解決策は、 "-std = C++ 11"の後に-DCGAL_ROOTを置くことです。

+0

あなたは本質的に私の答えの一部を繰り返しています、 "gmpライブラリがライブラリから見つからないかもしれません..."。その '-DCGAL_ROOT ="/path/to/CGAL-4.8.1 "はかなり奇妙なので、もっと詳しく説明する必要があります。私はそれがコンパイルプロセスに影響するのではないかと思う。 –

+1

'gmp'をlibarariesに追加した後も、コンパイルされませんでした。ソースからCGALをインストールし、インストールされたパスにリンクした後でのみコンパイルされます。また、これはDebian 8の問題と思われました。 Fedora20でエラーなしでコンパイルされました。 – scootie

関連する問題