I am trying to wrap c++ code into python, just one class to export with two functions. I compiled to to map.so and when I try to import map get error like noise
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: ./map.so: undefined symbol: _ZTIN5noise6module6ModuleE My c++ directory looks like (noise is dowwnloaded source code and all code is inside src)
/ map.cpp real_map.h real_map.cpp noise/ src/ .h and .cpp and new directory my CMakeLists.txt looks like
project (map) cmake_minimum_required(VERSION 2.8) find_package(PythonLibs) include_directories (${PYTHON_INCLUDE_DIRS}) find_package(Boost 1.45.0 COMPONENTS python) include_directories (${Boost_INCLUDE_DIRS}) add_library ( map SHARED WrappedMediumMapTile.cpp ) target_link_libraries (medium_map boost_python ${PYTHON_LIBRARIES} ${Boost_LIBRARIES} ) Does anyone have a clue what is a problem ?
My .cpp class which I want to wrap
#include <list> #include <iostream> #include <vector> #include <utility> #include <map> #include "noise/src/noise.h" #include "noiseutils/noiseutils.h" class MapTile { public: MapTile(float x1, float y1, float x2, float y2); ~MapTile(); void genHeightMaps(int resX, int resY); bool isPassable(float x, float y); bool isBuildable(float x, float y); protected: float parentX1; float parentY1; float parentX2; float parentY2; private: noise::module::RidgedMulti baseMountainTerrain; noise::module::ScaleBias mountainTerrain; noise::module::Billow baseFlatTerrain; noise::module::ScaleBias flatTerrain; noise::module::Perlin lowFreqBaseTerrainType; noise::module::Perlin mediumFreqBaseTerrainType; noise::module::Perlin highFreqBaseTerrainType; noise::module::Select baseTerrainType; noise::module::ScaleBias terrainType; noise::module::Const zero; noise::module::Perlin highHigh; noise::module::Select finalTerrain; noise::module::Select goldWoodDeposits; noise::utils::NoiseMap heightMapTerrain; noise::utils::NoiseMap heightMapGoldWood; noise::utils::Image image; }; and my wrap python
#include <boost/python.hpp> #include "MapTile.h" #include "noise/src/noise.h" #include "noiseutils/noiseutils.h" using namespace boost::python; BOOST_PYTHON_MODULE(map) // module name { class_<MapTile>("MapTile", init<float, float, float, float>()) .def("isPassable", &MapTile::isPassable) .def("isBuildable", &MapTile::isBuildable); }; Noise library is downloaded from http://sourceforge.net/projects/libnoise/files/libnoise%20sources/1.0.0/libnoisesrc-1.0.0.zip/download?use_mirror=garr&download= and used noise folder
c++filtsays_ZTIN5noise6module6ModuleEis mangled fortypeinfo for noise::module::Module, I would guess you have a virtual function that is not defined. If you include theModuleclass definition we can give you a definitive answer.noiseto thetarget_link_librarieslist in your CMakeLists.txt file. You may need to also addnoiseand/ornoise/srcto theinclude_directoriesas well.