From: cthulhum <dav...@bu...> - 2011-09-18 20:12:19
|
I'm currently trying to wrap a small C++ library with SWIG (though I only need to access methods from one class), with the goal of accessing one class and a few of its methods from python+numpy. My Extension setup looks like this : os.environ['CC'] = 'g++' _librf = Extension("_librf", sources = ["src/librf.i", "src/librf/librf/random_forest.cc", "src/librf/librf/tree.cc", "src/librf/librf/tree_node.cc", "src/librf/librf/weights.cc", "src/librf/librf/instance_set.cc", "src/librf/librf/discrete_dist.cc"], swig_opts=['-c++'], language='c++', include_dirs = [numpy_include]) And my SWIG config file is: %module librf %{ #define SWIG_FILE_WITH_INIT #include "librf/librf/random_forest.h" #include "librf/librf/tree.h" #include "librf/librf/tree_node.h" #include "librf/librf/weights.h" #include "librf/librf/instance_set.h" #include "librf/librf/discrete_dist.h" %} %feature("autodoc", "1"); %include "numpy.i" %init %{ import_array(); %} %apply (float* IN_ARRAY2, int DIM1, int DIM2) {(const float *data, int atts, int insts)}; %apply (int* IN_ARRAY1, int DIM1) {(const int *labels, int insts2)}; #include "librf/librf/random_forest.h" For the moment I'm just trying to get a single mapping to work (my constructor in random_forest.cc: RandomForest(const float *data, int atts, int insts, const int *labels,int insts2, int num_trees, int K, int min_size)), and can add more once I get the basics down. I'm not at all sure that I've set up my interface file correctly for what I want to do, but I'm equally unsure if that is the source of the errors I'm actually getting. Right now, when I run the setup script I get a stream of "undefined reference" errors once the script tries to build the .so: g++ build/temp.linux-x86_64-2.6/src/librf_wrap.o build/temp.linux-x86_64-2.6/src/librf/librf/random_forest.o build/temp.linux-x86_64-2.6/src/librf/librf/tree.o build/temp.linux-x86_64-2.6/src/librf/librf/tree_node.o build/temp.linux-x86_64-2.6/src/librf/librf/weights.o build/temp.linux-x86_64-2.6/src/librf/librf/instance_set.o build/temp.linux-x86_64-2.6/src/librf/librf/discrete_dist.o -o /home/davidjoh/workspace/ace_repo/acepy/_librf.so build/temp.linux-x86_64-2.6/src/librf_wrap.o: In function `SwigPyObject_richcompare': /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1536: undefined reference to `_Py_NotImplementedStruct' /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1540: undefined reference to `_Py_TrueStruct' /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1540: undefined reference to `_Py_ZeroStruct' build/temp.linux-x86_64-2.6/src/librf_wrap.o: In function `SWIG_Py_Void': /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1326: undefined reference to `_Py_NoneStruct' /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1326: undefined reference to `_Py_NoneStruct' /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1326: undefined reference to `_Py_NoneStruct' build/temp.linux-x86_64-2.6/src/librf_wrap.o: In function `_PySwigObject_type': /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1847: undefined reference to `PyObject_GenericGetAttr' /home/davidjoh/workspace/ace_repo/acepy/src/librf_wrap.cpp:1850: undefined reference to `PyType_Type' And so on. Any thoughts? Even lacking an explanation of the distutils failure, some hints as to whether I'm setting up my interface correctly would be handy. -- View this message in context: http://old.nabble.com/problems-with-swig-distutils-numpy-tp32482736p32482736.html Sent from the swig-user mailing list archive at Nabble.com. |