mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
1.06k stars 85 forks source link

Linker error with base units for "numerical_value_in()" #566

Closed sa2thoms closed 3 months ago

sa2thoms commented 5 months ago

I made a simple test program to try out the library (I am using Apple Clang 15). I am consuming the library using plain Cmake. I found an interesting problem where I can use the "numerical_value_in()" function for any combination of units except for the base units. For example:

speed.numerical_value_in(Mm/Ms) // works fine (megameters per megasecond)

speed.numerical_value_in(km/s) // works fine (kilometers per second)

speed.numerical_value_in(m/h) // works fine (meters per hour)

speed.numerical_value_in(m/s) // linker error!

This is the specific linker error I see: [build] "auto mp_units::detail::expr_divide<mp_units::derived_unit, mp_units::one, mp_units::detail::type_list_of_unit_less, mp_units::si::metre, mp_units::si::second>(mp_units::si::metre, mp_units::si::second)", referenced from: [build] auto mp_units::operator/<mp_units::si::metre, mp_units::si::second>(mp_units::si::metre, mp_units::si::second) in main.cpp.o [build] ld: symbol(s) not found for architecture arm64 [build] clang: error: linker command failed with exit code 1 (use -v to see invocation)

mpusz commented 5 months ago

Interesting, can you repro your specific case in the Compiler Explorer (https://godbolt.org)?

sa2thoms commented 5 months ago

Interesting, can you repro your specific case in the Compiler Explorer (https://godbolt.org)?

I cannot, at least not with clang 17 or clang 16. I guess compiler explorer can't use Apple Clang. I put my code in a public github repo though, so if you want to see exactly what I did it's here: https://github.com/sa2thoms/mp-units-sandbox/blob/main/src/main.cpp

mpusz commented 5 months ago

I do not have access to Apple, so I can't check if there is no repro with other compilers. Apple Clang 15 is a poor compiler, and I hope a new one will be released soon with better support.

sa2thoms commented 5 months ago

Okay, maybe I can just blame it on Apple then. I can always use something else. For my real (work) applications though, we are using MSVC for debugging and testing purposes sometimes, so that may pose a barrier to using this library for now, if we can't build in MSVC.

And of course we are compiling on Clang with localization disabled, so that needs to be solved.