Skip to content

Linker error when compiling nalgebra with const_fn_floating_point_arithmetic and generic_const_exprs #96561

Closed
@sakex

Description

@sakex

Symbols not found when compiling nalgebra on Mac (nightly-2022-03-12) with features. Also won't compile on the playground

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![feature(const_fn_floating_point_arithmetic)]

I tried this code:

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![feature(const_fn_floating_point_arithmetic)]

use nalgebra::{Matrix3x4, Matrix3, Vector3};
use std::ops::Mul;
pub type Point<const DIMENSION: usize> = nalgebra::geometry::Point<f64, DIMENSION>;

/// Returns a 3x3 rotation matrix that represents a rotation around
/// the x-axis in radians.
fn rotation_x(theta: f64) -> Matrix3<f64> {
    Matrix3::from([
        [1., 0., 0.],
        [0., theta.cos(), -theta.sin()],
        [0., theta.sin(), theta.cos()],
    ])
}

/// Returns a 3x3 rotation matrix that represents a rotation around
/// the y-axis in radians.
fn rotation_y(theta: f64) -> Matrix3<f64> {
    Matrix3::from([
        [theta.cos(), 0., theta.sin()],
        [0., 1., 0.],
        [-theta.sin(), 0., theta.cos()],
    ])
}

/// Returns a 3x3 rotation matrix that represents a rotation around
/// the z-axis in radians.
fn rotation_z(theta: f64) -> Matrix3<f64> {
    Matrix3::from([
        [theta.cos(), -theta.sin(), 0.],
        [theta.sin(), theta.cos(), 0.],
        [0., 0., 1.],
    ])
}

fn extrinsic_matrix(rotation: &Point<3>, position: &Point<3>) -> Matrix3x4<f64> {
    let [theta_x, theta_y, theta_z] = [rotation[0], rotation[1], rotation[2]];
    let rotation_x = rotation_x(theta_x);
    let rotation_y = rotation_y(theta_y);
    let rotation_z = rotation_z(theta_z);

    let mut rotation = rotation_z.mul(&rotation_y.mul(rotation_x));
    // Transpose the rotation
    let mut rotation_t = rotation.transpose();
    // Since the coordinate system 3D convention is to have the Y-axis point up (akin
    // to the OpenGL coordinate system y-axis), we  rotate the matrix 180 degrees around
    // the X-axis.
    rotation_t[(1, 0)] *= -1.;
    rotation_t[(1, 1)] *= -1.;
    rotation_t[(1, 2)] *= -1.;
    rotation_t[(2, 0)] *= -1.;
    rotation_t[(2, 1)] *= -1.;
    rotation_t[(2, 2)] *= -1.;

    let translate = (-1. * &rotation_t) * Vector3::from([position[0], position[1], position[2]]);
    let mut ret = rotation_t.insert_column(3, 0.);
    let mut last_col = ret.column_mut(3);
    last_col
        .iter_mut()
        .zip(translate.iter())
        .for_each(|(ptr, v)| *ptr = *v);

    ret
}

fn main() {
    let r = extrinsic_matrix(&Point::from([1.; 3]), &Point::from([1.;3]));
    println!("{:?}", r);
}

link to the playground

I expected to see this happen: Compile

Instead, this happened: Got a linker error:

/!\ Removing the unstable features fixes the problem

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (335ffbfa5 2022-03-11)
binary: rustc
commit-hash: 335ffbfa547df94ac236f5c56130cecf99c8d82b
commit-date: 2022-03-11
host: x86_64-apple-darwin
release: 1.61.0-nightly
LLVM version: 14.0.0
Backtrace

<backtrace>
= note: Undefined symbols for architecture x86_64:
            "_$LT$nalgebra..base..array_storage..ArrayStorage$LT$T$C$_$C$_$GT$$u20$as$u20$nalgebra..base..storage..RawStorage$LT$T$C$nalgebra..base..dimension..Const$LT$_$GT$$C$nalgebra..base..dimension..Const$LT$_$GT$$GT$$GT$::ptr::h949154e333f993d5", referenced from:
                nalgebra::base::edition::_$LT$impl$u20$nalgebra..base..matrix..Matrix$LT$T$C$R$C$C$C$S$GT$$GT$::insert_columns_generic_uninitialized::ha573b9be5f695339 in project-name-e927f780dcb49716.qoe91ck1hn8iql5.rcgu.o
            "_$LT$nalgebra..base..default_allocator..DefaultAllocator$u20$as$u20$nalgebra..base..allocator..Reallocator$LT$T$C$RFrom$C$CFrom$C$nalgebra..base..dimension..Const$LT$_$GT$$C$nalgebra..base..dimension..Const$LT$_$GT$$GT$$GT$::reallocate_copy::h532649383ab34c69", referenced from:
                nalgebra::base::edition::_$LT$impl$u20$nalgebra..base..matrix..Matrix$LT$T$C$R$C$C$C$S$GT$$GT$::insert_columns_generic_uninitialized::ha573b9be5f695339 in project-name-e927f780dcb49716.qoe91ck1hn8iql5.rcgu.o
            "_$LT$nalgebra..base..dimension..Const$LT$_$GT$$u20$as$u20$nalgebra..base..dimension..DimName$GT$::name::ha195183af6b5b677", referenced from:
                _$LT$nalgebra..base..dimension..Const$LT$_$GT$$u20$as$u20$nalgebra..base..dimension..DimAdd$LT$nalgebra..base..dimension..Const$LT$_$GT$$GT$$GT$::add::h0b8d3820b030c62d in project-name-e927f780dcb49716.1of6v2rwyn1blawe.rcgu.o
            "nalgebra::base::matrix::Matrix$LT$T$C$R$C$C$C$S$GT$::from_data::hbacd65a216967352", referenced from:
                nalgebra::base::edition::_$LT$impl$u20$nalgebra..base..matrix..Matrix$LT$T$C$R$C$C$C$S$GT$$GT$::insert_columns_generic_uninitialized::ha573b9be5f695339 in project-name-e927f780dcb49716.qoe91ck1hn8iql5.rcgu.o
            "nalgebra::base::matrix_slice::_$LT$impl$u20$nalgebra..base..matrix..Matrix$LT$T$C$R$C$C$C$S$GT$$GT$::fixed_columns_mut::h1fb1ae9d239f8874", referenced from:
                nalgebra::base::edition::_$LT$impl$u20$nalgebra..base..matrix..Matrix$LT$T$C$R$C$C$C$S$GT$$GT$::insert_fixed_columns::h0ffeb2b4b2ff09af in project-name-e927f780dcb49716.qoe91ck1hn8iql5.rcgu.o
            "nalgebra::base::matrix::Matrix$LT$core..mem..maybe_uninit..MaybeUninit$LT$T$GT$$C$R$C$C$C$$LT$nalgebra..base..default_allocator..DefaultAllocator$u20$as$u20$nalgebra..base..allocator..Allocator$LT$T$C$R$C$C$GT$$GT$..BufferUninit$GT$::assume_init::ha7e8b0c078e33716", referenced from:
                nalgebra::base::edition::_$LT$impl$u20$nalgebra..base..matrix..Matrix$LT$T$C$R$C$C$C$S$GT$$GT$::insert_fixed_columns::h0ffeb2b4b2ff09af in project-name-e927f780dcb49716.qoe91ck1hn8iql5.rcgu.o
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
 </backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`requires-incomplete-featuresThis issue requires the use of incomplete features.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions