This might have already been posted somewhere else but I couldn't find anything that worked. I have the following libraries / tools installed :
boost:
boost-python36.x86_64
boost-python36-devel.x86_64
boost-python36-static.x86_64
Python API:
python3-devel.x86_64
Here's my node.h file:
#pragma once
#include <python3.6m/Python.h>
#include <boost/python.hpp>
#include <boost/python/make_constructor.hpp>
#include <boost/python/detail/api_placeholder.hpp>
using namespace std;
using namespace boost::python;
class Node{
public:
Node(PyObject* attr);
~Node();
PyObject* _attr;
static int number_of_nodes;
int id;
// other functions
};
node.cpp:
#include "node.h"
using namespace std;
//using namespace boost::python;
int Node::number_of_nodes = 0;
Node::Node(PyObject* attr){
this->id = number_of_nodes;
number_of_id++;
this->_attr = attr;
}
Node::~Node(){
}
// other functions
BOOST_PYTHON_MODULE(Node){
class_<Node>("Node", init<PyObject*>())
// other functions
}
Makefile:
node.o:node.h node.cpp
g++ -std=c++11 -fPIC -I/usr/include/python3.6m node.cpp -c -lpython3.6m -lboost_python3
Node.so:node.o
g++ -std=c++11 -L /lib64 -shared node.o -o Node.so -lpython3.6m -lboost_python3
So far it works : no warnings, no compile errors. The .so file gets compiled without any issues.
the python file :
import Node # Node.so
When I try to run it, I get this error:
dynamic module does not define init function (initNode)
I checked online and apparently this can be caused by the name of the .so file not matching with the name of the module. However I made sure that the name is Node and the .so file is Node.so. Is there something I'm missing? I didn't see an explicit "initClassName" in any of the boost module I saw online.
Thanks