You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've searched other issues and no duplicate issues were found.
I've agreed with the maintainers that I can plan this task.
Description
Autoware relies a lot on ROS2 components, which are nothing but shared library.
Because it is totally fine for a shared library to contain undefined symbols, the linker won't complain if it is the case at compilation time.
However, if you try to load into a ROS2 container a component with undefined symbols at runtime, then your application will crash.
Not catching undefined symbols when compiling components is thus quite annoying.
One solution is to add tests or to link it to a binary, but this means extra compilation time.
Another simple solution is to pass -Wl,--no-undefined to the target libraries.
For example, I have commented a function definition in gnss_poser_node.cpp, then I have added the following line to autoware_cmake:
# DIRTY? add -Wl,--no-undefined to *ALL* shared librariesadd_link_options(
"$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:LINKER:--no-undefined>")
With this extra flag, I get the following compilation error:
/home/sig/autoware/src/universe/autoware.universe/sensing/gnss_poser/src/gnss_poser_core.cpp:46: undefined reference to `gnss_poser::GNSSPoser::callbackMapProjectorInfo(std::shared_ptr<tier4_map_msgs::msg::MapProjectorInfo_<std::allocator<void> > const>)'
collect2: error: ld returned 1 exit status
Whereas without the flag no error is reported (but the application would crash at runtime).
Purpose
Detect broken components at compilation time
Possible approaches
Add the flag to all shared libraries: add_link_options("$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:LINKER:--no-undefined>")
Or add target_link_options(tgt PRIVATE LINKER:--no-undefined) to individual components.
Definition of done
Depend on chosen solution
The text was updated successfully, but these errors were encountered:
VRichardJP
changed the title
Add -Wl,--no-undefined to make compilation of shared library fail if a symbol is not defined?
Add -Wl,--no-undefined to make compilation of components fail if a symbol is not defined?
Jul 29, 2024
Checklist
Description
Autoware relies a lot on ROS2 components, which are nothing but shared library.
Because it is totally fine for a shared library to contain undefined symbols, the linker won't complain if it is the case at compilation time.
However, if you try to load into a ROS2 container a component with undefined symbols at runtime, then your application will crash.
Not catching undefined symbols when compiling components is thus quite annoying.
One solution is to add tests or to link it to a binary, but this means extra compilation time.
Another simple solution is to pass
-Wl,--no-undefined
to the target libraries.For example, I have commented a function definition in gnss_poser_node.cpp, then I have added the following line to
autoware_cmake
:With this extra flag, I get the following compilation error:
Whereas without the flag no error is reported (but the application would crash at runtime).
Purpose
Detect broken components at compilation time
Possible approaches
Add the flag to all shared libraries:
add_link_options("$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:LINKER:--no-undefined>")
Or add
target_link_options(tgt PRIVATE LINKER:--no-undefined)
to individual components.Definition of done
Depend on chosen solution
The text was updated successfully, but these errors were encountered: