Skip to content

cmake: Use --whole-archive to export ouster_client symbols#518

Closed
ovaag wants to merge 1 commit intoouster-lidar:masterfrom
scoutdi:lib-linking
Closed

cmake: Use --whole-archive to export ouster_client symbols#518
ovaag wants to merge 1 commit intoouster-lidar:masterfrom
scoutdi:lib-linking

Conversation

@ovaag
Copy link
Copy Markdown
Contributor

@ovaag ovaag commented Mar 10, 2026

671fc0a fixes the double-free by removing --whole-archive and linking ${OUSTER_TARGET_LINKS} directly to each internal target (nodelets, tests). This works within the ouster_ros package, but breaks external downstream catkin packages.

Since ouster_client remains PRIVATE to ouster_ros, only symbols referenced by os_ros.cpp end up in libouster_ros.so — everything else is stripped by the linker. Downstream packages that on ouster_ros get libouster_ros.so via catkin but have no way to access unreferenced ouster_client symbols (e.g. make_xyz_lut, sensor config APIs). The internal workaround of linking ${OUSTER_TARGET_LINKS} directly isn't available to external packages since ouster_client is a static library that isn't installed or exported.

this commit solves this by using --whole-archive as PUBLIC on ouster_ros only, so all ouster_client symbols are bundled into libouster_ros.so and visible to downstream consumers. The original double-free was caused by --whole-archive being applied to both ouster_ros and the nodelets, linking ouster_client twice into the same process. Applying it only to ouster_ros avoids this.

Related Issues & PRs

Summary of Changes

Validation

External packages using ouster_client libs now builds

ouster_client was linked PRIVATE to ouster_ros, so only symbols directly
used by ouster_ros sources were included in the shared library. Downstream
packages linking against libouster_ros.so could not access other
ouster_client symbols (e.g. make_xyz_lut). Use --whole-archive to bundle
all ouster_client symbols into the shared library.
target_link_libraries(ouster_ros
PUBLIC ${catkin_LIBRARIES} ouster_build OusterSDK::ouster_sensor pcl_common
PRIVATE ${OUSTER_TARGET_LINKS}
-Wl,--whole-archive ${OUSTER_TARGET_LINKS} -Wl,--no-whole-archive
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to remain PRIVATE

Suggested change
-Wl,--whole-archive ${OUSTER_TARGET_LINKS} -Wl,--no-whole-archive
PRIVATE -Wl,--whole-archive ${OUSTER_TARGET_LINKS} -Wl,--no-whole-archive

It should still be possible to link against your downstream package.

@Samahu
Copy link
Copy Markdown
Contributor

Samahu commented Mar 11, 2026

Included in #521 with other fixes

@Samahu
Copy link
Copy Markdown
Contributor

Samahu commented Mar 11, 2026

Included in #521 with other fixes

other than keeping the PRIVATE I have ensured this code still compiles on MacOS as the --whole-archive flag is a gnu specific. MacOS have a different token for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants