From d0a40ca31f761aadfdbda6d261552f84ea27846d Mon Sep 17 00:00:00 2001 From: Rainer Kuemmerle Date: Sat, 24 Feb 2024 15:08:32 +0100 Subject: [PATCH] Fix registration of types into factory Force linking the factory registration singletons in the g2opy wrapper. This should fix usage of the factory when statically linking the g2o libraries. --- CMakeLists.txt | 2 ++ python/types/icp/py_types_icp.cpp | 3 +++ python/types/sba/py_types_sba.cpp | 3 +++ python/types/sba/py_types_six_dof_expmap.cpp | 3 +++ python/types/sclam2d/py_types_sclam2d.cpp | 3 +++ python/types/sim3/py_types_seven_dof_expmap.cpp | 3 +++ python/types/slam2d/py_types_slam2d.cpp | 3 +++ python/types/slam3d/py_types_slam3d.cpp | 3 +++ 8 files changed, 23 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f05c281b..52dc8588f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,8 @@ option (BUILD_SHARED_LIBS "Build Shared Libraries (preferred and required for th set (G2O_LIB_TYPE STATIC) if (BUILD_SHARED_LIBS) set (G2O_LIB_TYPE SHARED) +else() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) endif() # On the Mac platform, configure the RPATH as per the INSTALL, to diff --git a/python/types/icp/py_types_icp.cpp b/python/types/icp/py_types_icp.cpp index e07b11e05..70d2e9acd 100644 --- a/python/types/icp/py_types_icp.cpp +++ b/python/types/icp/py_types_icp.cpp @@ -2,11 +2,14 @@ #include +#include "g2o/core/factory.h" #include "g2opy.h" #include "python/core/py_base_binary_edge.h" #include "python/core/py_base_edge.h" #include "python/core/py_base_vertex.h" +G2O_USE_TYPE_GROUP(icp) + namespace g2o { void declareTypesICP(py::module& m) { diff --git a/python/types/sba/py_types_sba.cpp b/python/types/sba/py_types_sba.cpp index bdee6e7f7..b1ce05a0b 100644 --- a/python/types/sba/py_types_sba.cpp +++ b/python/types/sba/py_types_sba.cpp @@ -1,11 +1,14 @@ #include "py_types_sba.h" +#include "g2o/core/factory.h" #include "g2o/types/sba/types_sba.h" #include "g2o/types/sba/vertex_intrinsics.h" #include "g2opy.h" #include "python/core/py_base_binary_edge.h" #include "python/core/py_base_vertex.h" +G2O_USE_TYPE_GROUP(sba) + namespace g2o { namespace { diff --git a/python/types/sba/py_types_six_dof_expmap.cpp b/python/types/sba/py_types_six_dof_expmap.cpp index 4cb908e5c..73c6bccf2 100644 --- a/python/types/sba/py_types_six_dof_expmap.cpp +++ b/python/types/sba/py_types_six_dof_expmap.cpp @@ -1,5 +1,6 @@ #include "py_types_six_dof_expmap.h" +#include "g2o/core/factory.h" #include "g2o/types/sba/edge_project_xyz.h" #include "g2o/types/sba/types_six_dof_expmap.h" #include "g2o/types/slam3d/se3quat.h" @@ -9,6 +10,8 @@ #include "python/core/py_base_unary_edge.h" #include "python/core/py_base_variable_sized_edge.h" +G2O_USE_TYPE_GROUP(expmap) + namespace g2o { void declareTypesSixDofExpmap(py::module& m) { diff --git a/python/types/sclam2d/py_types_sclam2d.cpp b/python/types/sclam2d/py_types_sclam2d.cpp index 7f1371b1b..61ce8c398 100644 --- a/python/types/sclam2d/py_types_sclam2d.cpp +++ b/python/types/sclam2d/py_types_sclam2d.cpp @@ -1,10 +1,13 @@ #include "py_types_sclam2d.h" +#include "g2o/core/factory.h" #include "py_edge_se2_odom_differential_calib.h" #include "py_edge_se2_sensor_calib.h" #include "py_odometry_measurement.h" #include "py_vertex_odom_differential_params.h" +G2O_USE_TYPE_GROUP(sclam) + namespace g2o { void declareTypesSclam2d(py::module& m) { diff --git a/python/types/sim3/py_types_seven_dof_expmap.cpp b/python/types/sim3/py_types_seven_dof_expmap.cpp index 2f1f24090..4d5222f8e 100644 --- a/python/types/sim3/py_types_seven_dof_expmap.cpp +++ b/python/types/sim3/py_types_seven_dof_expmap.cpp @@ -1,10 +1,13 @@ #include "py_types_seven_dof_expmap.h" +#include "g2o/core/factory.h" #include "g2o/types/sim3/types_seven_dof_expmap.h" #include "g2opy.h" #include "py_sim3.h" #include "python/core/py_base_binary_edge.h" +G2O_USE_TYPE_GROUP(sim3) + namespace g2o { void declareTypesSevenDofExpmap(py::module& m) { diff --git a/python/types/slam2d/py_types_slam2d.cpp b/python/types/slam2d/py_types_slam2d.cpp index a5bd5a846..13186b055 100644 --- a/python/types/slam2d/py_types_slam2d.cpp +++ b/python/types/slam2d/py_types_slam2d.cpp @@ -1,5 +1,6 @@ #include "py_types_slam2d.h" +#include "g2o/core/factory.h" #include "py_edge_pointxy.h" #include "py_edge_se2.h" #include "py_edge_se2_pointxy.h" @@ -8,6 +9,8 @@ #include "py_vertex_point_xy.h" #include "py_vertex_se2.h" +G2O_USE_TYPE_GROUP(slam2d) + namespace g2o { void declareTypesSlam2d(py::module& m) { diff --git a/python/types/slam3d/py_types_slam3d.cpp b/python/types/slam3d/py_types_slam3d.cpp index faa3a41ca..c51785fa3 100644 --- a/python/types/slam3d/py_types_slam3d.cpp +++ b/python/types/slam3d/py_types_slam3d.cpp @@ -1,5 +1,6 @@ #include "py_types_slam3d.h" +#include "g2o/core/factory.h" #include "py_edge_pointxyz.h" #include "py_edge_se3.h" #include "py_edge_se3_pointxyz.h" @@ -8,6 +9,8 @@ #include "py_vertex_pointxyz.h" #include "py_vertex_se3.h" +G2O_USE_TYPE_GROUP(slam3d) + namespace g2o { void declareTypesSlam3d(py::module& m) {