Skip to content

Module fails to build with recursive lazy load error #717

@JoeBot21

Description

@JoeBot21

I'm having trouble getting the mp-units module to build on nixos 25.05 with the following shell.nix and packages versions:

# shell.nix
let
  pkgs = import <nixpkgs> {};
in
pkgs.mkshell {
  packages = with pkgs; [
    cmake
    gcc15
    gsl-lite
    ninja
  ];
}
  • CMake 3.31.6
  • GCC 15.1.0
  • Ninja 1.12.1
  • gsl-lite 0.43.0

The following CMakeLists.txt and main.cpp produce the error.

# CMakeLists.txt
cmake_minimum_required(version 3.31.0)
project(import-test LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)

include(FetchContent)
FetchContent_Declare(
  mp-units
  GIT_REPOSITORY https://github.com/mpusz/mp-units
  GIT_TAG d9dce46c21f6d915424112fd8b5e2163addc051b
  SOURCE_SUBDIR src
)
set(MP_UNITS_BUILD_CXX_MODULES ON)
set(MP_UNITS_API_STD_FORMAT ON)
FetchContent_MakeAvailable(mp-units)

add_library(import-test SHARED src/import-test/main.cpp)
target_link_libraries(import-test PRIVATE mp-units::mp-units)
// main.cpp
import mp_units;

int main() {}

Output from cmake --build

[5/10] Building CXX object _deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp-units-systems.cpp.o
FAILED: _deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp-units-systems.cpp.o _deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp_units.systems.gcm 
/nix/store/abv8wwll56z9nxv33d5sk6ywwmnga397-gcc-wrapper-15.1.0/bin/g++ -DMP_UNITS_API_CONTRACTS=2 -DMP_UNITS_API_NATURAL_UNITS=1 -DMP_UNITS_API_NO_CRTP=1 -DMP_UNITS_API_STD_FORMAT=1 -DMP_UNITS_HOSTED=1 -I/home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/include -I/home/joebot/git/mpy-units/build/_deps/mp-units-src/src/core/include -std=gnu++23 -MD -MT _deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp-units-systems.cpp.o -MF _deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp-units-systems.cpp.o.d -fmodules-ts -fmodule-mapper=_deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp-units-systems.cpp.o.modmap -MD -fdeps-format=p1689r5 -x c++ -o _deps/mp-units-build/systems/CMakeFiles/mp-units-systems.dir/mp-units-systems.cpp.o -c /home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/mp-units-systems.cpp
In file included from /home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/include/mp-units/systems/angular/math.h:28,
                 from /home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/include/mp-units/systems/angular.h:29,
                 from /home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/mp-units-systems.cpp:37:
/home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/include/mp-units/systems/angular/units.h:39:43: error: recursive lazy load
   39 | inline constexpr struct dim_angle final : base_dimension<"A"> {} dim_angle;
      |                                           ^~~~~~~~~~~~~~
/home/joebot/git/mpy-units/build/_deps/mp-units-src/src/systems/include/mp-units/systems/angular/units.h:39:43: fatal error: failed to load pendings for ‘mp_units::detail::power_v’
compilation terminated.
ninja: build stopped: subcommand failed.

Setting MP_UNITS_BUILD_CXX_MODULES OFF in CMakeLists.txt and including the mp-units headers builds successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions