First of all, I am relatively new to C++ programming and pybind11. The following example should explain my problem:
a.h:
namespace test {
class A {
public:
static int something;
};
void setSomething(int input);
}
a.cpp:
#include <pybind11/pybind11.h>
#include "a.h"
int test::A::something;
void test::setSomething(int input) {
A::something = input;
}
PYBIND11_MODULE(a, handle) {
handle.doc() = "I'm a docstring hehe";
handle.def("setSomething", &test::setSomething);
}
b.h:
namespace test {
class B {
public:
B();
int getSomething() const;
};
}
b.cpp:
#include <pybind11/pybind11.h>
#include "a.h"
#include "b.h"
namespace py = pybind11;
// int test::A::something;
test::B::B(){}
int test::B::getSomething() const {
return A::something;
}
PYBIND11_MODULE(b, handle) {
handle.doc() = "I'm a docstring hehe";
py::class_<test::B>(handle, "B")
.def(py::init())
.def("getSomething", &test::B::getSomething);
}
So I have two classes A and B, which are defined in a.cpp and b.cpp that both have header files a.h and b.h. Basically, I am trying to access the static variable from class A in class B. Now if I compile them using CMake and try to run a test.py file I get an ImportError telling me undefined symbol: _ZN4test1A9somethingE. I hope this is not a stupid question. Thanks for your help in advance!
Edit: If I define the variable within the class, it doesn't acquire the value set before or after outside the class.