I was following this tutorial from boost.python
to create a shared library. Here's a simple code defining the methods that I want to expose to python.
#include <boost/python.hpp>
#include <iostream>
const int oneforth(int num, int bound) {
if (num < bound) {return num;}
return oneforth(num * (1/4), bound);
}
BOOST_PYTHON_MODULE(modd) //python module name
{
using namespace boost::python;
def("oneforth", oneforth); //python method
}
int main() {
std::cout << oneforth(10, 4);
return 0;
}
ai
I want to expose oneforth
function so I can use from modd import oneforth
.
I'm building the shared library *.so
using -
g++ -c -fPIC py.cpp -o py.o
g++ -shared py.so py.o
whenever I trying to import the dynamic py.so
, I get erros like undefined symbol
. What am I doing wrong? How does one create a shared library this way?