nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
955 stars 135 forks source link

Undefined references to .name() and .abbreviation() #298

Open Elbereth9001 opened 1 year ago

Elbereth9001 commented 1 year ago

Invoking any of the following:

produces an unreadable mess of a linker error, when:

Invoking these for constexpr values turns them into compile-time errors of the functions being "used but never defined". I take it that this behaviour is intentional? The only reference I've found to this is in the release notes of 2.3.0:

  • Adds std::cout support for units with no defined abbreviation (they show up as a combination of SI base units)

But there is no further information on why they would not be defined. Since the whole point of the library is about being safe at compile-time, I would expect that the abbreviation could also be constructed at compile-time, since all of the types are known at compile-time. Obviously the name does not always exist for all unit combinations.

Would it be feasible to have one or more of the following?

Tested with: Units 2.3.1, Clang 14.0 Units 2.3.3, GCC 9.4.0

Unreadable linker error: linker_error

Compile-time error: compiler_error

Code: maincpp.txt

ibensw commented 3 months ago

I see the same issue with gcc 11.4, and units v2.3.3. Did you find a way to workaround the issue?