I need to use cppyy to call functions from a 3rd-party C++ library in Python. To start I wrote a simple C++ function and tried to load it in Python:
test.hpp
class Test {
public:
void test();
};
test.cpp
#include <iostream>
#include "test.hpp"
void Test::test() {
std::cout << "Hello World!" << std::endl;
}
I then create test.dll
with the following command line (I'm on Windows now, but the final
project should run on a Jetson Nano with Ubuntu 20.04):
g++ -shared test.hpp test.cpp -o testlib.dll
test.py
import cppyy
cppyy.include('test.hpp')
cppyy.load_library('testlib.dll')
from cppyy.gbl import Test
t = Test()
t.test()
This code crashes on the last line t.test()
with the following error:
IncrementalExecutor::executeFunction: symbol '?Y@X@@QEAAXXZ' unresolved while linking symbol '__cf_8'!
You are probably missing the definition of public: void __cdecl X::Y(void) __ptr64
Maybe you need to load the corresponding shared library?
I tried to look for solutions online but didn't find much, the only thing I tried was something about adding __declspec(dllexport)
in the class definition but that didn't help, and I never really worked with C++ before and couldn't understand most of the rest, so any help would be appreciated.
Thank you in advance.