Replies: 2 comments 3 replies
-
I think this is actually very similar to Issue #78. Here's my theory: Because diff --git a/repositories/rosbag2.BUILD.bazel b/repositories/rosbag2.BUILD.bazel
index 0a3db1b..a9c196c 100644
--- a/repositories/rosbag2.BUILD.bazel
+++ b/repositories/rosbag2.BUILD.bazel
@@ -15,15 +15,15 @@ load("@com_github_mvukov_rules_ros2//ros2:plugin.bzl", "ros2_plugin")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_ros2_pip_deps//:requirements.bzl", "requirement")
-ros2_cpp_library(
- name = "rosbag2_storage",
+ros2_cpp_binary(
+ name = "rosbag2_storage.so",
srcs = glob([
+ "rosbag2_storage/include/**/*.hpp",
"rosbag2_storage/src/**/*.cpp",
"rosbag2_storage/src/**/*.hpp",
]),
- hdrs = glob(["rosbag2_storage/include/**/*.hpp"]),
includes = ["rosbag2_storage/include"],
- visibility = ["//visibility:public"],
+ linkshared = True,
deps = [
"@ros2_pluginlib//:pluginlib",
"@ros2_rcpputils//:rcpputils",
@@ -32,6 +32,17 @@ ros2_cpp_library(
],
)
+ros2_cpp_library(
+ name = "rosbag2_storage",
+ srcs = ["rosbag2_storage.so"],
+ hdrs = glob(["rosbag2_storage/include/**/*.hpp"]),
+ includes = ["rosbag2_storage/include"],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":rosbag2_storage.so",
+ ],
+)
+
ros2_plugin(
name = "rosbag2_storage_default_plugins",
srcs = glob([ Not sure if there are other (direct or indirect) dependencies of |
Beta Was this translation helpful? Give feedback.
-
Thanks for all the details. I'm not that versed with linkers and gcc/clang impl details. BTW, I also saw this thing a while back 🤯 https://github.com/ros2/rosbag2/blob/96c11b073c9bf56fb35586205b941e14f8f15b6a/rosbag2_py/test/common.py#L20 . Anyway, just for my understanding: for your use-case we need both diffs in place, right? Or only the first one? Speaking out loud, would I am open to alternatives. For me it's also fine to to try out https://bazel.build/reference/be/c-cpp#cc_shared_library instead of cc_binary+cc_library hack. Whatever comes out of this, let's set up CI for clang+libc++ as well. |
Beta Was this translation helpful? Give feedback.
-
Starting this primarily as a discussion since this might be a bit of a weird use case. I've been trying to link a unit test using
rosbag2_ccp::Reader
with clang + lld with llvm's libc++ implementation of the standard library. I've run into problems which might be related to Issue #78. In particular, at runtime, this dynamic_cast results in anullptr
due (approximately) to the mechanism discussed here under "dynamic_cast, throw, typeid don't work with shared libraries". I think this is due to the way typeinfo is handled by default in libc++. I'm currently using the clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz binary release for this and I've been solving this problem so far by using the following patch formvukov/rules_ros2
:I think this works because it ensures type_info objects needed for the aforementioned dynamic_cast (i.e.
class_loader::impl::AbstractMetaObject<T>
for anyT
) are included in the dynamic symbols table of any executable that links@ros2_class_loader//:class_loader
. This allows the dynamic cast to work correctly, but I can't help but feel like there must be a better solution to this problem.If I instead link the standard library (i.e.
-lstdc++
), I can verify based on thetypeinfo
header that string comparison is being used fortype_info
objects (rather than pointer comparison) so the dynamic_cast appears to just work in this case.Apologies for my limited understanding of the underlying issues. I'm happy to put together an example to reproduce this if folks would like.
Beta Was this translation helpful? Give feedback.
All reactions