2016-10-14 6 views
1

私はCで書いたライブラリを持っており、Pythonからアクセスする必要があるので、Boost.Pythonを使ってラップしました。私はこれがcommonであることをfoundBoost.Pythonモジュールを読み込めません - 未定義のシンボル

ImportError: ./tropmodboost.so: undefined symbol: _Z12simplex_freeP7simplex 

:私は、問題なくファイルの.soブーストに私のライブラリをコンパイルすることができますが、私は(import tropmodboost付き)のPythonにそれをロードしようとすると、私は次のエラーを取得します私のg ++​​リンカ呼び出しで-lディレクティブを並べ替えることはしばしば修正できますが、私が私の言うことができるのはすでに大丈夫です。ここで

はUbuntuの上で実行されている私のMakefileのテキスト、です:

# location of the Python header files 
PYTHON_VERSION = 2.7 
PY_VER2  = 27 

# various include directories, used separately in different compiler tasks 
PYN_INC = /usr/include/python$(PYTHON_VERSION) 
IGH_INC = /usr/local/include/igraph 
BST_INC = /usr/include 

# library locations for linking 
LS = -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -L/usr/lib/python$(PYTHON_VERSION)/config 
lS = -lboost_python-py$(PY_VER2) -lpython$(PYTHON_VERSION) 

# source files for different compiler tasks 
CORE_SRC = permutation_src.c permutation_parity.c split.c simplex.c simplex_src.c build_complex.c 
TEST_SRC = main.c tests/tests.c -ligraph -lm 

# objects for linking the core to the boost module 
CORE_OBJS = permutation_src.o permutation_parity.o split.o simplex.o simplex_src.o build_complex.o 

.PHONY: clean tests 

main: tropmod.boost.o 
    g++ -shared -Wl,--export-dynamic tropmod.boost.o $(LS) $(lS) $(CORE_OBJS) -o tropmodboost.so 

tropmod.boost.o: tropmod.boost.cpp tmstuff 
    g++ -I$(PYN_INC) -I$(BST_INC) -I$(IGH_INC) -fPIC -c tropmod.boost.cpp 

tmstuff: main.c permutation_src.c permutation_parity.c split.c simplex.c simplex_src.c tests/tests.c 
    gcc -I. -I=$(IGH_INC) -fPIC -c $(CORE_SRC) 

debug: main.c permutation_src.c permutation_parity.c split.c simplex.c simplex_src.c tests/tests.c 
    gcc -I. -I=$(IGH_INC) -g -fPIC -c $(CORE_SRC) 

tests: 
    gcc -I. -I=$(IGH_INC) -g -o tmtest $(CORE_SRC) $(TEST_SRC) -L/usr/local/lib -ligraph -lm 

clean: 
    rm *.o *.so 

ldd tropmodboost.so出力を呼び出す:

linux-vdso.so.1 => (0x00007ffff79a3000) 
libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f34ea732000) 
libboost_python-py27.so.1.58.0 => /usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.58.0 (0x00007f34ea4e6000) 
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f34ea163000) 
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f34e9f4d000) 
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f34e9b84000) 
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f34e9966000) 
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f34e974c000) 
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f34e9548000) 
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f34e9344000) 
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f34e903b000) 
/lib64/ld-linux-x86-64.so.2 (0x0000561fcfee3000) 

をここで.HPPファイルから除くブーストラッパーコード自体を示しています:

#include <boost/python/class.hpp> 
#include <boost/python/module.hpp> 
#include <boost/python/def.hpp> 
#include <boost/python/list.hpp> 
#include <boost/python/object.hpp> 

[...] 

BOOST_PYTHON_MODULE(tropmodboost) { 

    using namespace boost::python; 

    class_<ConfigSpace>("ConfigSpace", init<int, int>()) 
     .def("destroy", &ConfigSpace::destroy) 
     .def("getTraceOfPerm", &ConfigSpace::getTraceOfPerm) 
     ; 


} 

答えて

1

nmを数回実行した後私のオブジェクトファイルの中で、定義されていないシンボル_Z12simplex_freeP7simplexがsimplex.oでちょうどsimplex_freeと定義されていることがわかりました。おそらくgccを使ってsimplex.cからコンパイルされていたからです。言い換えれば、gccとg ++は別々に命名していると思いますので、すべてをg ++に切り替え、CコードをC++としてコンパイルして問題を解決しました。

関連する問題