extendr / rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically
https://extendr.github.io/rextendr/
Other
181 stars 27 forks source link

Error in rextendr::document() "undefined reference to 'R_init_rust_utils_extendr' #245

Closed Jaage closed 1 year ago

Jaage commented 1 year ago

I have been following this guide: https://cran.r-project.org/web/packages/rextendr/vignettes/package.html to create an R package that calls Rust code. My Rust code runs fine in Rust and when called with rust_source(), but is failing when trying to create a package:

> rextendr::document()
ℹ Generating extendr wrapper functions for package: rust.utils.
ℹ Re-compiling rust.utils (debug build)
── R CMD INSTALL ────────────────────────────────────────────────────────────

─  installing *source* package 'rust.utils' ...

   ** using staged installation

   ** libs

   rm -Rf rust.utils.dll ./rust/target/x86_64-pc-windows-gnu/release/librust_utils.a entrypoint.o

   gcc  -I"C:/PROGRA~1/R/R-42~1.1/include" -DNDEBUG     -I"C:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall -gdwarf-2 -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -UNDEBUG -Wall -pedantic -g -O0 -c entrypoint.c -o entrypoint.o

   mkdir -p ./rust/target/libgcc_mock

   # `rustc` adds `-lgcc_eh` flags to the compiler, but Rtools' GCC doesn't have

   # `libgcc_eh` due to the compilation settings. So, in order to please the

   # compiler, we need to add empty `libgcc_eh` to the library search paths.

   #

   # For more details, please refer to

   # https://github.com/r-windows/rtools-packages/blob/2407b23f1e0925bbb20a4162c963600105236318/mingw-w64-gcc/PKGBUILD#L313-L316

   touch ./rust/target/libgcc_mock/libgcc_eh.a

   # CARGO_LINKER is provided in Makevars.ucrt for R >= 4.2

   export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="x86_64-w64-mingw32.static.posix-gcc.exe" && \

      export LIBRARY_PATH="${LIBRARY_PATH};/c/Users/jorda/Documents/CIG/cig_prob_est/inla_models/rust.utils/src/./rust/target/libgcc_mock" && \
        cargo build --target=x86_64-pc-windows-gnu --lib --release --manifest-path=./rust/Cargo.toml --target-dir ./rust/target

       Finished release [optimized] target(s) in 1.59s

   gcc -shared -static-libgcc -o rust.utils.dll rust.utils-win.def entrypoint.o -L./rust/target/x86_64-pc-windows-gnu/release -lrust_utils -lws2_32 -ladvapi32 -luserenv -lbcrypt -LC:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/rtools42/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-42~1.1/bin/x64 -lR

C

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: entrypoint.o: in function `R_init_rust_utils':
   C:\Users\jorda\Documents\CIG\cig_prob_est\inla_models\rust.utils\src/entrypoint.c:7: undefined reference to `R_init_rust_utils_extendr'

   collect2.exe: error: ld returned 1 exit status

   make: *** [C:/PROGRA~1/R/R-42~1.1/share/make/winshlib.mk:16: rust.utils.dll] Error 1

   ERROR: compilation failed for package 'rust.utils'

─  removing 'C:/Users/jorda/AppData/Local/Temp/RtmpYHikEy/devtools_install_15e03bf41c51/rust.utils'

Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Type .Last.error to see the more details.

Here is the .Last.error:

> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Backtrace:
 1. rextendr::document()
 2. rextendr::register_extendr(path = pkg, quiet = quiet)
 3. pkgbuild::compile_dll(path = path, quiet = quiet, force = compile)
 4. pkgbuild:::install_min(path, dest = install_dir, components = "libs", args = if (n…
 5. pkgbuild::rcmd_build_tools("INSTALL", c(path, paste("--library=", dest, …
 6. pkgbuild::with_build_tools({ …
 7. withr::with_path(rtools_path(), code)
 8. base::force(code)
 9. base::withCallingHandlers(callr::rcmd_safe(..., env = env, spinner = FALSE, …
10. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, …
11. callr:::run_r(options)
12. base::with(options, with_envvar(env, do.call(processx::run, c(list(bin, …
13. base::with.default(options, with_envvar(env, do.call(processx::run, …
14. base::eval(substitute(expr), data, enclos = parent.frame())
15. base::eval(substitute(expr), data, enclos = parent.frame())
16. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs…
17. base::force(code)
18. base::do.call(processx::run, c(list(bin, args = real_cmdargs, stdout_line_cal…
19. (function (command = NULL, args = character(), error_on_status = TRUE, …
20. base::throw(new_process_error(res, call = sys.call(), echo = echo, …
21. | base::signalCondition(cond)
22. (function (e) …
23. asNamespace("callr")$err$throw(e)

And here is my particularly long function and rust_source() arguments:

use rand_distr::{Normal, Distribution};
use polars::prelude::*;
use std::time::Instant;
use rayon::prelude::*;
use ndarray::Array2;
use itertools::izip;
#[macro_use]
extern crate fstrings;

#[extendr]
fn get_probs(n: i32, means: Vec<f64>, sds: Vec<f64>, a: Vec<i32>, 
    b: Vec<i32>, c: Vec<i32>, d: Vec<i32>, param: &str, c_adjust: bool) -> Robj {

    let start = Instant::now();
    let n: usize = n.try_into().unwrap();
    let mut preds: Array2<f64> = Array2::zeros((means.len(), n));

    preds.axis_iter_mut(ndarray::Axis(0)).into_par_iter().enumerate().for_each(|(i, mut row)| {

        let mut rng = rand::thread_rng();
        (0..n).into_iter().for_each(|j| {
            let normal = Normal::new(means[i], sds[i]).unwrap();
            row[j as usize] = normal.sample(&mut rng);
        })
    });

    let mut df: DataFrame = DataFrame::new(
        preds.axis_iter(ndarray::Axis(1))
            .into_par_iter()
            .enumerate()
            .map(|(i, col)| {
                Series::new(
                    &f!("{i}"),
                    col.to_vec()
                )
            })
            .collect::<Vec<Series>>()
        ).unwrap();

    let sample_cols= (0..n as i32).collect::<Vec<i32>>()
        .par_iter()
        .map(|l| format!("{}", l))
        .collect::<Vec<String>>();

    df.with_column(Series::new("a", a)).unwrap();
    df.with_column(Series::new("b", b)).unwrap();
    df.with_column(Series::new("c", c)).unwrap();
    df.with_column(Series::new("d", d)).unwrap();

    let mut df = df.melt(&["a", "b", "c", "d"], sample_cols).unwrap();

    df.with_column(Series::new("variable", df.column("variable").unwrap().cast(&DataType::Int32).unwrap())).unwrap();

    let width = df.shape().0 as i32;

    let b_samples = 
        izip!(
            df.column("b").unwrap().i32().unwrap().into_no_null_iter().collect::<Vec<i32>>(),
            df.column("variable").unwrap().i32().unwrap().into_no_null_iter().collect::<Vec<i32>>()
        )
        .into_iter().map(|(a, b)| a + b * width ).collect::<Vec<i32>>();

    let b_sample_cs = 
        izip!(
            df.column("b").unwrap().i32().unwrap().into_no_null_iter().collect::<Vec<i32>>(),
            df.column("variable").unwrap().i32().unwrap().into_no_null_iter().collect::<Vec<i32>>(),
            df.column("c").unwrap().i32().unwrap().into_no_null_iter().collect::<Vec<i32>>()
        )
        .into_iter().map(|(i, j, k)| i + j * width + k * width * width).collect::<Vec<i32>>();

    df.with_column(Series::new("b_sample", b_samples)).unwrap();
    df.with_column(Series::new("b_sample_c", b_sample_cs)).unwrap();

    let mut df = df.sort(&["b_sample", "value"], false).unwrap();

    if c_adjust {
        df = df
            .lazy()
            .filter(col("b_sample_c").is_first())
            .collect()
            .unwrap();
    } else {}

    df.with_column(
        Series::new("ones", std::iter::repeat(1).take(df.shape().0).collect::<Vec<i32>>())).unwrap();

    let df = df.lazy()
        .select([
            all().exclude(["ones"]),
            col("ones").cumsum(false).over(["b_sample"]).list().explode().alias("rank")
        ]).collect().unwrap();

    let params = match param {

        "opt1" => {
            let opt1 = df.lazy().groupby_stable(["d", "rank"]).agg([
                all().first(),
                (col("value").count() / (n as f64).into()).alias("prob")
            ]).collect().unwrap();

            let mut opt1 = opt1.lazy()
                .select([
                    col("d"),
                    col("prob")
                ])
                .collect().unwrap();

            opt1.with_column(Series::new("d", opt1.column("d").unwrap().cast(&DataType::Float64).unwrap())).unwrap();

            Ok::<DataFrame, PolarsError>(opt1)
        },

        "opt2" => {

            let mut opt2 = df.clone().lazy().groupby_stable(["b_sample"]).agg([
                col("b").first()
            ]).collect().unwrap();

            opt2.with_column(Series::new(
                "first",
                df.filter(&df.column("rank").unwrap().equal(1).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();
            opt2.with_column(Series::new(
                "second",
                df.filter(&df.column("rank").unwrap().equal(2).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();

            let opt2 = opt2.clone().lazy().select([
                all(),
                concat_str(&[col("first"), col("second")], "_").alias("temp")
            ]).collect().unwrap();

            let opt2 = opt2.clone().lazy().groupby_stable(["b", "temp"]).agg([
                all().opt2clude(&["b_sample"]).first(),
                (col("b").count() / (n as f64).into()).alias("prob")
            ]).collect().unwrap();

            let mut opt2 = opt2.lazy()
                .select([
                    col("b"),
                    col("first"),
                    col("second"),
                    col("prob")
                ])
                .collect().unwrap();

            opt2.with_column(Series::new("b", opt2.column("b").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt2.with_column(Series::new("first", opt2.column("first").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt2.with_column(Series::new("second", opt2.column("second").unwrap().cast(&DataType::Float64).unwrap())).unwrap();

            Ok(opt2)
        },

        "opt3" => {
            let df = df.clone().lazy()
                .select([
                    all(),
                    col("c").count().over([col("b_sample")]).alias("group_size")
                ])
                .collect().unwrap();

            let df = df.filter(&df.column("group_size").unwrap().gt(2).unwrap()).unwrap().drop("group_size").unwrap();

            let mut opt3 = df.clone().lazy().groupby_stable(["b_sample"]).agg([
                col("b").first()
            ]).collect().unwrap();

            opt3.with_column(Series::new(
                "first",
                df.filter(&df.column("rank").unwrap().equal(1).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();
            opt3.with_column(Series::new(
                "second",
                df.filter(&df.column("rank").unwrap().equal(2).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();
            opt3.with_column(Series::new(
                "third",
                df.filter(&df.column("rank").unwrap().equal(3).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();

            let opt3 = opt3.clone().lazy().select([
                all(),
                concat_str(&[col("first"), col("second"), col("third")], "_").alias("temp")
            ]).collect().unwrap();

            let opt3 = opt3.clone().lazy().groupby_stable(["b", "temp"]).agg([
                all().exclude(&["b_sample"]).first(),
                (col("b").count() / (n as f64).into()).alias("prob")
            ]).collect().unwrap();

            let mut opt3 = opt3.lazy()
                .select([
                    col("b"),
                    col("first"),
                    col("second"),
                    col("third"),
                    col("prob")
                ])
                .collect().unwrap();

            opt3.with_column(Series::new("b", opt3.column("b").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt3.with_column(Series::new("first", opt3.column("first").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt3.with_column(Series::new("second", opt3.column("second").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt3.with_column(Series::new("third", opt3.column("third").unwrap().cast(&DataType::Float64).unwrap())).unwrap();

            Ok(opt3)
        },

        "opt4" => {
            let df = df.lazy()
                .select([
                    all(),
                    col("c").count().over([col("b_sample")]).alias("group_size")
                ])
                .collect().unwrap();

            let df = df.filter(&df.column("group_size").unwrap().gt(3).unwrap()).unwrap().drop("group_size").unwrap();

            let mut opt4 = df.clone().lazy().groupby_stable(["b_sample"]).agg([
                col("b").first()
            ]).collect().unwrap();

            opt4.with_column(Series::new(
                "first",
                df.filter(&df.column("rank").unwrap().equal(1).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();
            opt4.with_column(Series::new(
                "second",
                df.filter(&df.column("rank").unwrap().equal(2).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();
            opt4.with_column(Series::new(
                "third",
                df.filter(&df.column("rank").unwrap().equal(3).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();
            opt4.with_column(Series::new(
                "fourth",
                df.filter(&df.column("rank").unwrap().equal(4).unwrap()).unwrap().column("c").unwrap())
            ).unwrap();

            let opt4 = opt4.lazy().select([
                all(),
                concat_str(&[col("first"), col("second"), col("third"), col("fourth")], "_").alias("temp")
            ]).collect().unwrap();

            let opt4 = opt4.lazy().groupby_stable(["b", "temp"]).agg([
                all().exclude(&["b_sample"]).first(),
                (col("b").count() / (n as f64).into()).alias("prob")
            ]).collect().unwrap();

            let mut opt4 = opt4.lazy()
                .select([
                    col("b"),
                    col("first"),
                    col("second"),
                    col("third"),
                    col("fourth"),
                    col("prob")
                ])
                .collect().unwrap();

            opt4.with_column(Series::new("b", opt4.column("b").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt4.with_column(Series::new("first", opt4.column("first").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt4.with_column(Series::new("second", opt4.column("second").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt4.with_column(Series::new("third", opt4.column("third").unwrap().cast(&DataType::Float64).unwrap())).unwrap();
            opt4.with_column(Series::new("fourth", opt4.column("fourth").unwrap().cast(&DataType::Float64).unwrap())).unwrap();

            Ok(opt4)
        },

        _ => panic!("Incorrect param type")
    }.unwrap();

    let duration = start.elapsed();
    rprintln!("{:?}", duration);
    params.to_ndarray::<Float64Type>().unwrap().try_into().unwrap()
}

rust_source(

    code = code,

    dependencies = list(
        `ndarray` = list(
            version = "0.15.6",
            features = array("rayon", 1L)
        ),
        `polars` = list(
            git = "https://github.com/pola-rs/polars",
            features = c("concat_str", "cum_agg", "is_first", "lazy", "rank", "strings", "performant", "cse", "ndarray", "nightly")
        ),
        `fstrings` = "0.2.3",
        `itertools` = "0.10.5",
        `rand` = "0.8.5",
        `rand_distr` = "0.4.3",
        `rayon` = "1.6.1"),

    extendr_deps = list(

        `extendr-api` = list(

            git = "https://github.com/extendr/extendr",

            features = array("ndarray", 1L)

        )

    ),
    profile = "release"

)

Is this guide up to date, or is there a better resource to follow for this procedure? Thanks a lot.

Jaage commented 1 year ago

So I am a dumb end user who did not have ///@export and

extendr_module! {
    mod rustUtils;
    fn get_probs;
}

With those, I get a different error:

Finished release [optimized] target(s) in 1.43s

   gcc -shared -static-libgcc -o rustUtils.dll rustUtils-win.def entrypoint.o -L./rust/target/x86_64-pc-windows-gnu/release -lrustUtils -lws2_32 -ladvapi32 -luserenv -lbcrypt -LC:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/rtools42/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-42~1.1/bin/x64 -lR

C

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(dirs_sys-75c82abcdc21f926.dirs_sys.8e88a5c2-cgu.2.rcgu.o):dirs_sys.8e88a5c2-:(.text+0x4d): undefined reference to `CoTaskMemFree'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(dirs_sys-75c82abcdc21f926.dirs_sys.8e88a5c2-cgu.2.rcgu.o):dirs_sys.8e88a5c2-:(.text+0x74): undefined reference to `CoTaskMemFree'

C

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x89): undefined reference to `RtlGetVersion'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0xc77): undefined reference to `NtQueryInformationProcess'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0xcf0): undefined reference to `EnumProcessModulesEx'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0xd28): undefined reference to `GetModuleBaseNameW'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0xd98): undefined reference to `GetModuleFileNameExW'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinf

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x13c9): undefined reference to `GetModuleFileNameExW'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x276c): undefined reference to `NtQueryInformationProcess'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x2872): undefined reference to `NtQueryInformationProcess'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x389e): undefined reference to `NtQueryInformationProcess'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x3916): undefined reference to `NtQueryInformationProcess'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.1.rcgu.o):sysinfo.2ae7d728-c:(.text+0x3a00): undefined reference to `GetProcessMemoryInfo'

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.3.rcgu.o):sysinfo.2ae7d728-c:(.text+0x856): undefined reference to `CoUninitialize'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x7c): undefined reference to `PdhOpenQueryA'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0xa2): undefined reference to `PdhAddEnglishCounterA'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0xb0): undefined reference to `PdhCloseQuery'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0xfa): undefined reference to `PdhCollectQueryDataEx'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x15b): undefined reference to `PdhRemoveCounter'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-win

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x165): undefined reference to `PdhCloseQuery'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x4ea): undefined reference to `PdhGetFormattedCounterValue'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x66b): undefined reference to `PdhRemoveCounter'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x6ca): undefined reference to `PdhCloseQuery'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x6fc): undefined reference to `PdhOpenQueryA'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x89f): undefined reference to `PdhGetFormattedCounterValue'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0xa27): undefined reference to `PdhAddEnglishCounterW'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinf

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0xad5): undefined reference to `PdhCollectQueryData'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.4.rcgu.o):sysinfo.2ae7d728-c:(.text+0x153f): undefined reference to `CallNtPowerInformation'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x74c): undefined reference to `PdhRemoveCounter'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x771): undefined reference to `PdhCloseQuery'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0xe1c): undefined reference to `PdhRemoveCounter'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0xe3f): undefined reference to `PdhCloseQuery'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x1758): undefined reference to `GetPerformanceInfo'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x1c7b): undefined reference to `PdhCollectQueryData'
C:\rtools42\x86_64-w64-mingw32.static.po

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x1dcf): undefined reference to `PdhOpenQueryA'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x1eae): undefined reference to `PdhRemoveCounter'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x1ed1): undefined reference to `PdhCloseQuery'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x22b7): undefined reference to `GetPerformanceInfo'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x266d): undefined reference to `GetProcessMemoryInfo'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.5.rcgu.o):sysinfo.2ae7d728-c:(.text+0x2902): undefined reference to `NtQuerySystemInformation'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/libru

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xad): undefined reference to `CoUninitialize'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x384): undefined reference to `CoInitializeEx'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x3e9): undefined reference to `CoInitializeSecurity'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x447): undefined reference to `CoCreateInstance'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x541): undefined reference to `CoSetProxyBlanket'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-p

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x6f2): undefined reference to `CoInitializeEx'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x757): undefined reference to `CoInitializeSecurity'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x7b5): undefined reference to `CoCreateInstance'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x8af): undefined reference to `CoSetProxyBlanket'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xc78): undefined reference to `SysAllocString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xcbe): undefined reference to `SysFreeString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xd8b): undefined reference to `SysAllocString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xd9a): undefined reference to `SysAllocString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xdd6): undefined reference to `SysFreeString'
C

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xdde): undefined reference to `SysFreeString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xf0b): undefined reference to `SysAllocString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xf4d): undefined reference to `SysFreeString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xf57): undefined reference to `VariantClear'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d72

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xf82): undefined reference to `SysAllocString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xfb0): undefined reference to `SysFreeString'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0xfba): undefined reference to `VariantClear'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.6.rcgu.o):sysinfo.2ae7d728-c:(.text+0x10dc): undefined reference to `CoUninitialize'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0x6fa): undefined reference to `NetUserEnum'
C:\rtools42\x86_64-w64-mingw32.stati

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0x7f5): undefined reference to `NetUserGetLocalGroups'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0x82a): undefined reference to `NetApiBufferFree'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0xaf9): undefined reference to `NetApiBufferFree'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0xb2a): undefined reference to `LsaEnumerateLogonSessions'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0xb95): undefined reference to `LsaGetLogonSessionData'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.7.rcgu.o):sysinfo.2ae7d728-c:(.text+0xdaa): undefined reference to `LsaFreeReturnBuffer'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.9.rcgu.o):sysinfo.2ae7d728-c:(.text+0xc83): undefined reference to `GetAdaptersAddresses'
C:\rtools42\x86_64-w64-mingw32.static.posix\bin

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.9.rcgu.o):sysinfo.2ae7d728-c:(.text+0xd4a): undefined reference to `GetAdaptersAddresses'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.9.rcgu.o):sysinfo.2ae7d728-c:(.text+0xd8b): undefined reference to `GetAdaptersAddresses'

C

   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.11.rcgu.o):sysinfo.2ae7d728-c:(.text+0x7c1): undefined reference to `GetIfTable2'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.11.rcgu.o):sysinfo.2ae7d728-c:(.text+0x117d): undefined reference to `FreeMibTable'
   C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/librustUtils.a(sysinfo-d7211667ceae4265.sysinfo.2ae7d728-cgu.11.rcgu.o):sysinfo.2ae7d728-c:(.text+0x1477): undefined reference to `GetIfEntry2'

   collect2.exe: error: ld returned 1 exit status

   make: *** [C:/PROGRA~1/R/R-42~1.1/share/make/winshlib.mk:16: rustUtils.dll] Error 1

   ERROR: compilation failed for package 'rustUtils'

─  removing 'C:/Users/jorda/AppData/Local/Temp/RtmpYHikEy/devtools_install_15e05bac5cdc/rustUtils'

Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Type .Last.error to see the more details.
Jaage commented 1 year ago

I was able to solve this by linking all the libraries these C functions come from by adding -lole32 -lntoskrnl -lpsapi -lpdh -lpowrprof -loleaut32 -lnetapi32 -lsecur32 -liphlpapi to my Makevars.win.

Do I need to do something in the future so that these get linked by default?

yutannihilation commented 1 year ago

Good that you solved the problem! It seems Polars requires these libraries.

https://github.com/pola-rs/r-polars/blob/63c883769e1de80bcb9c475e8ac04d280eafae40/src/Makevars.win#L9

Do I need to do something in the future so that these get linked by default?

Like this one, you might need to add extra libraries to PKG_LIBS. As it's very much depends on what dependencies you use, I think there's no general advice here.