I have a my_class.h:
// my_class.h
namespace N
{
class my_class
{
public:
void hello_world();
};
}
with a my_class.cpp file.
// my_class.cpp
extern "C" {
#include "my_class.h"
}
#include <iostream>
using namespace N;
using namespace std;
void my_class::hello_world()
{
cout << "Hello, World!" << endl;
}
I want to create a shared object my_class.so file to use it in python.
Therefore, I am using the g++ compiler.
g++ -fPIC -shared -o my_class.so my_class.cpp
Using the shared object in python my_class.so
import ctypes
my_class = ctypes.cdll.LoadLibrary('./my_class.so')
my_class.hello_world
I get the following error message:
Exception has occurred: AttributeError
./my_class.so: undefined symbol: hello_world
I do not know how to interpret this.
Note:
my_class.hello_world()results the same error
extern "C"wrapper inmy_class.cpp? It is still not working even without it.