Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rextendr::document(): linker fails with "undefined reference to `BCryptGenRandom'" #165

Closed
markusgumbel opened this issue Dec 27, 2021 · 9 comments

Comments

@markusgumbel
Copy link

markusgumbel commented Dec 27, 2021

I have cloned the helloextendr repo and run rextendr::document() on a Windows 11 computer. This fails with
collect2.exe: error: ld returned 1 exit status. Apparently, the linker could not find a reference to 'BCryptGenRandom'.

Maybe this issue is related to #19.

Here's the full protocol. My environment is shown below.

> rextendr::document()
i Generating extendr wrapper functions for package: helloextendr.
! No library found at src/helloextendr.dll, recompilation is required.
Re-compiling helloextendr
-  installing *source* package 'helloextendr' ...
   ** using staged installation
   ** libs
   rm -Rf helloextendr.dll ./rust/target/x86_64-pc-windows-gnu/release/libhelloextendr.a entrypoint.o
   "C:/lib/R/Rtools40v2/mingw64/bin/"gcc  -I"c:/PROGRA~1/R/R-41~1.2/include" -DNDEBUG          -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -UNDEBUG -Wall -pedantic -g -O0 -c entrypoint.c -o entrypoint.o
   cargo build --target=x86_64-pc-windows-gnu --lib --release --manifest-path=./rust/Cargo.toml
      Compiling winapi v0.3.9
      Compiling proc-macro2 v1.0.35
      Compiling unicode-xid v0.2.2
      Compiling syn v1.0.84
      Compiling extendr-engine v0.2.0
      Compiling lazy_static v1.4.0
      Compiling quote v1.0.10
      Compiling libR-sys v0.2.2
      Compiling extendr-macros v0.2.0
      Compiling extendr-api v0.2.0
      Compiling helloextendr v0.1.0 (C:\Users\Markus\Local-Docs\src\R\helloextendr\src\rust)
       Finished release [optimized] target(s) in 18.18s
   C:/lib/R/Rtools40v2/mingw64/bin/gcc -shared -s -static-libgcc -o helloextendr.dll tmp.def entrypoint.o -L./rust/target/x86_64-pc-windows-gnu/release -lhelloextendr -lws2_32 -ladvapi32 -luserenv -Lc:/PROGRA~1/R/R-41~1.2/bin/x64 -lR
   C:/lib/R/Rtools40v2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./rust/target/x86_64-pc-windows-gnu/release/libhelloextendr.a(std-57e8ea4e1cfb36e3.std.0253c85e-cgu.0.rcgu.o): in function `std::sys::windows::rand::hashmap_random_keys':
   /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys\windows/rand.rs:10: undefined reference to `BCryptGenRandom'
   C:/lib/R/Rtools40v2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys\windows/rand.rs:10: undefined reference to `BCryptGenRandom'
   collect2.exe: error: ld returned 1 exit status
   no DLL was created
   ERROR: compilation failed for package 'helloextendr'
-  removing 'C:/Users/Markus/AppData/Local/Temp/RtmpC6Z6MD/devtools_install_77644144103c/helloextendr'
Fehler in (function (command = NULL, args = character(), error_on_status = TRUE,  :
  System command 'Rcmd.exe' failed, exit status: 1, stdout & stderr were printed
Type .Last.error.trace to see where the error occurred

rextendr was freshly installed from github.

R version:
version.string R version 4.1.2 (2021-11-01)

R Tools:
The latest version (4.0v2) found on https://cran.r-project.org/bin/windows/Rtools/rtools40.html .

Rust:

>rustc -V
rustc 1.57.0 (f1edd0429 2021-11-29)

Prepared according to https://cran.r-project.org/bin/windows/Rtools/rtools40.html .

>rustup show
Default host: x86_64-pc-windows-gnu
rustup home:  C:\Users\Markus\.rustup

installed targets for active toolchain
--------------------------------------

i686-pc-windows-gnu
i686-pc-windows-msvc
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.57.0 (f1edd0429 2021-11-29)
@CGMossa
Copy link
Member

CGMossa commented Dec 27, 2021

This is my guess: You need to have the active toolchain to be "stable-gnu", e.g. x86_64-pc-windows-gnu.
This can be accomplished in several ways. You can override the directory with rustup to use that by default.

See rustup override for information, or just do rustup override set stable-gnu.

But for now, just set the default building across everything to this by:

rustup default stable-gnu

and try to see if this changes things. And go from there.

@yutannihilation
Copy link
Contributor

yutannihilation commented Dec 27, 2021

@markusgumbel

rextendr was freshly installed from github.

I guess you created the package with the version before #156 gets merged, as no -lbcrypt is included in this line.

C:/lib/R/Rtools40v2/mingw64/bin/gcc -shared -s -static-libgcc -o helloextendr.dll tmp.def entrypoint.o -L./rust/target/x86_64-pc-windows-gnu/release -lhelloextendr -lws2_32 -ladvapi32 -luserenv -Lc:/PROGRA~1/R/R-41~1.2/bin/x64 -lR

You need to tweak your src/Makevars.win by yourself (or recreate the package from the fresh template), sorry for inconvenience!

-PKG_LIBS = -L$(LIBDIR) -l{{{pkg_name}}} -lws2_32 -ladvapi32 -luserenv
+PKG_LIBS = -L$(LIBDIR) -l{{{pkg_name}}} -lws2_32 -ladvapi32 -luserenv -lbcrypt

@Ilia-Kosenkov
As it seems the users are getting to hit this issue, can we consider releasing the next version? I mean this is not very urgent, so have a happy holidays :)

@Ilia-Kosenkov
Copy link
Member

Yeah, I think we should try releasing after holidays, but not before we fix the problem with MacOS builds.

@yutannihilation
Copy link
Contributor

I see. #166 will solve the issue.

@markusgumbel
Copy link
Author

Thanks a lot @CGMossa , @yutannihilation and @Ilia-Kosenkov.

Adding -lbcrypt in makevars.win worked!

@yutannihilation
Copy link
Contributor

Thanks for confirming! Let me open this issue for a while so that the users can discover the solution when they hit the same error.

I have cloned the helloextendr repo

Sorry, I missed this comment. Maybe we should update it to match the latest template...

@Ilia-Kosenkov
Copy link
Member

@yutannihilation , I made an issue there extendr/helloextendr#12. Also, there is an error in the docs as pointed out in extendr/helloextendr#11.

@yutannihilation
Copy link
Contributor

Thanks!

@Ilia-Kosenkov
Copy link
Member

This is already fixed in our templates, so will not be an issue once the next version of {rextendr} is on CRAN.

hpwxf added a commit to libKriging/libkrigingtemplate that referenced this issue Sep 3, 2023
hpwxf added a commit to libKriging/libkrigingtemplate that referenced this issue Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants