I am trying to combine a few modules, created by pybind11 and unfortunately can't get it to work. Hopefully someone can help out. I have tried to simplify the problem as much as possible.
Am trying to create the following two modules:
point
: can be called directlyline
: can be called directly and also uses point module.
point.h:
#ifndef UNTITLED1_POINT_H
#define UNTITLED1_POINT_H
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
class Point {
private:
double m_x;
double m_y;
double m_z;
public:
Point()= default;
Point(double x, double y, double z);
};
PYBIND11_MODULE(point, m) {
py::class_<Point>(m, "Point")
.def(py::init<double, double, double>());
}
#endif //UNTITLED1_POINT_H
point.cpp:
#include "point.h"
Point::Point (double x, double y, double z){
m_x = x;
m_y = y;
m_z = z;
}
line.h:
#ifndef UNTITLED1_LINE_H
#define UNTITLED1_LINE_H
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
#include "point.h"
class Line {
private:
Point m_p1;
Point m_p2;
public:
Line(Point p1, Point p2);
};
PYBIND11_MODULE(line, m) {
py::class_<Line>(m, "line")
.def(py::init<Point, Point>());
}
#endif //UNTITLED1_LINE_H
line.cpp:
#include "line.h"
Line::Line(Point p1, Point p2) {
m_p1 = p1;
m_p2 = p2;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(untitled1)
set(CMAKE_CXX_STANDARD 11)
add_subdirectory(pybind11)
pybind11_add_module(point point.cpp)
pybind11_add_module(line line.cpp)
Now the following python code is run:
from point import point
from line import line
p1 = point(1, 2, 3)
p2 = point(3, 4, 5)
l = line(p1, p2)
leading to a undefined symbol error:
Symbol not found: __ZN5pointC1Eddd
Update:
I have also tried the following lines in the cmake file:
pybind11_add_module(point SHARED point.cpp)
pybind11_add_module(line line.cpp)
target_link_libraries(line PRIVATE point)
Update: more precise error: