gxf_isaac_gems: make MachineEpsilon specializations inline - #76
Open
wolfv wants to merge 1 commit into
Open
Conversation
epsilon.hpp declares a variable template and two explicit specializations:
template <typename K>
constexpr K MachineEpsilon = K(0);
template <>
constexpr float MachineEpsilon<float> = 5.9604644775390625e-8f;
template <>
constexpr double MachineEpsilon<double> = 1.11022302462515654e-16;
In C++17 `constexpr` implies `inline` for variables, but an explicit
specialization of a variable template is not a template -- it is an ordinary
variable declaration, and the implicit inline does not apply to it. Each
translation unit including the header therefore emits its own definition with
external linkage, and linking two such objects together fails:
ld: detection3_d_array_message.cpp.o:(.rodata+0x38): multiple definition of
'nvidia::isaac::MachineEpsilon<double>';
nitros_detection3_d_array.cpp.o:(.rodata+0x48): first defined here
ld: detection3_d_array_message.cpp.o:(.rodata+0x40): multiple definition of
'nvidia::isaac::MachineEpsilon<float>'; ...
collect2: error: ld returned 1 exit status
Adding `inline` gives the specializations vague linkage so the definitions are
merged, which is what the primary template already gets.
Hit while building isaac_ros_nitros_detection3_d_array_type from source with GCC
15 and binutils ld. It is latent rather than new: any two translation units in one
target that both include epsilon.hpp will collide, so it depends on how the
sources happen to be grouped.
Signed-off-by: Wolf Vollprecht <w.vollprecht@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
epsilon.hpp declares a variable template and two explicit specializations:
In C++17
constexprimpliesinlinefor variables, but an explicit specialization of a variable template is not a template -- it is an ordinary variable declaration, and the implicit inline does not apply to it. Each translation unit including the header therefore emits its own definition with external linkage, and linking two such objects together fails:Adding
inlinegives the specializations vague linkage so the definitions are merged, which is what the primary template already gets.Hit while building isaac_ros_nitros_detection3_d_array_type from source with GCC 15 and binutils ld. It is latent rather than new: any two translation units in one target that both include epsilon.hpp will collide, so it depends on how the sources happen to be grouped.