rdotnet/rClr

Building with VS2019 and R 3.6.0 Fails

tvidvei opened this issue · 4 comments

Hi,
I try to compile and build rClr using VS2019 and R 3.6.0. The compilation works fine, but the build, using devtools::build, fails late in the process. Here are the error messages at the end of the output log from devtools::build:

** building package indices
   ** installing vignettes
   ** testing if installed package can be loaded from temporary location
   Error: package or namespace load failed for 'rClr':
    .onLoad failed in loadNamespace() for 'rClr', details:
     call: fun(libname, pkgname)
     error: rClr library .NET framework not found - looked under C:/Users/tovi85/AppData/Local/Temp/Rtmp4S1KM6/Rinst7474233f586e/00LOCK-rClr/00new/rClr/libs//x64 but not found in 
   Error: loading failed
   Execution halted
   ERROR: loading failed
-  removing 'C:/Users/tovi85/AppData/Local/Temp/Rtmp4S1KM6/Rinst7474233f586e/rClr'
         -----------------------------------
   ERROR: package installation failed
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command error

I have tried to follow the instructions by running setup_vcpp.cmd, and setting the environmentvariables in accordance with the setup on my machine. I'm a little bit surprised that build() complains about missing ".NET Framework" in the temporary directory. ClrFacade is set up to compile with .NET Standard 2.0 - not .NET Framework.

I have been struggling with this problem for hours now, and hope for any ideas or suggestions on how to solve this problem!

Here is info about the setup on my machine:

Visual Studio 2019, version 16.03
R version 3.6.0 installed in C:\Programs\R\R-3.6.0
RStudio 1.2.1335
rClr code in C:\git0\rClr:  commit d2a3591 on master, 2019-06-10 with minor changes:
- in configure.win, row 114: VS_COMNTOOLS="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools"
- in src/setup_vcpp.cmd, row 59: set VSDEVENV="%VSCOMNTOOLS%\..\..\VC\Auxiliary\build\vcvarsall.bat"

Below is the full output log FYI.

Best regards,
Tor Vidvei

> rClrPkg = devtools::build(pkg = rClrPath)
√  checking for file 'c:\git0\rClr/DESCRIPTION' (453ms)
-  preparing 'rClr': (3.8s)
√  checking DESCRIPTION meta-information ... 
-  cleaning src
-  running 'cleanup.win'
-  installing the package to build vignettes (1.4s)
         -----------------------------------
-  installing *source* package 'rClr' ...
   ** using staged installation
   warning: Path to the Mono SDK not found by querying the Windows registry. Mono support will be disabled
   R_HOME=C:/Programs/R/R-36~1.0
   C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe
   **********************************************************************
   ** Visual Studio 2019 Developer Command Prompt v16.0.3
   ** Copyright (c) 2019 Microsoft Corporation
   **********************************************************************
      Creating library C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\libfiles\x64\Rdll.lib and object C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\libfiles\x64\Rdll.exp
      Creating library C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\libfiles\i386\Rdll.lib and object C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\libfiles\i386\Rdll.exp
      Creating library C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\libfiles\i386\mono-2.0.lib and object C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\libfiles\i386\mono-2.0.exp
   ** libs
     running 'src/Makefile.win' ...
   **Variable information only for diagnosis purposes**
   Windows architecture /x64
   env variable TEMP is /Users/tovi85/AppData/Local/Temp
   env variable TMP is /Users/tovi85/AppData/Local/Temp
   BuildConfiguration=Release
   BuildMonoSupport=False
   Mono Build configuration MonoInstall
   R_ARCH=/x64
   OBJECTS=
   SHLIB_EXT=
   CC=cc
   CXX=g++
   ALL_CFLAGS=
   ALL_CPPFLAGS=
   build cmd line: C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe rClr.sln //t:Build //p:Configuration=Release //p:Platform=replaced_tgt_platform //consoleloggerparameters:ErrorsOnly
   **END Variable**
   nuget.exe  restore rClr.sln ;
   MSBuild auto-detection: using msbuild version '16.0.461.62831' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin'.
   Restoring packages for C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\ClrFacade.csproj...
   Restoring packages for C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\RclrTests\RclrTests.csproj...
   Committing restore...
   Generating MSBuild file C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\obj\ClrFacade.csproj.nuget.g.props.
   Generating MSBuild file C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\obj\ClrFacade.csproj.nuget.g.targets.
   Writing assets file to disk. Path: C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\obj\project.assets.json
   Restore completed in 957,8 ms for C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\ClrFacade.csproj.
   Committing restore...
   Generating MSBuild file C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\RclrTests\obj\RclrTests.csproj.nuget.g.props.
   Writing assets file to disk. Path: C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\RclrTests\obj\project.assets.json
   Restore completed in 2,34 sec for C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\RclrTests\RclrTests.csproj.
   
   NuGet Config files used:
       C:\Users\tovi85\AppData\Roaming\NuGet\NuGet.Config
       C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
   
   Feeds used:
       C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
       https://api.nuget.org/v3/index.json
   Microsoft (R) Build Engine version 4.7.3190.0
   [Microsoft .NET Framework, version 4.0.30319.42000]
   Copyright (C) Microsoft Corporation. All rights reserved.
   
   Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
   C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\rClr.vcxproj(55,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
   C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\ClrFacade.csproj(24,39): error MSB4066: The attribute "Version" in element <PackageReference> is unrecognized.
   C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\RclrTests\RclrTests.csproj(22,14): error MSB4066: The attribute "Remove" in element <Compile> is unrecognized.
   Microsoft (R) Build Engine version 4.7.3190.0
   [Microsoft .NET Framework, version 4.0.30319.42000]
   Copyright (C) Microsoft Corporation. All rights reserved.
   
   Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
   C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\rClr.vcxproj(55,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
   C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\ClrFacade.csproj(24,39): error MSB4066: The attribute "Version" in element <PackageReference> is unrecognized.
   r_architecture=x64;\
   RCLRBINDIR=./x64/Release;\
   bin_dir=$RCLRBINDIR; \
   RCLRBINS="rClrMs.dll rClrMs.exp rClrMs.lib rClrMs.pdb" ; \
   cmd /c win_cp.cmd $bin_dir ../inst/libs/$r_architecture/ $RCLRBINS;
   
   2019/06/11 17:45:56 ERROR 3 (0x00000003) Accessing Source Directory C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\x64\Release\
   The system cannot find the path specified.
   r_architecture=i386;\
   RCLRBINDIR=./Release;\
   bin_dir=$RCLRBINDIR; \
   RCLRBINS="rClrMs.dll rClrMs.exp rClrMs.lib rClrMs.pdb" ; \
   cmd /c win_cp.cmd $bin_dir ../inst/libs/$r_architecture/ $RCLRBINS;
   
   2019/06/11 17:45:56 ERROR 2 (0x00000002) Accessing Source Directory C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\Release\
   The system cannot find the file specified.
   bin_dir=./MonoInstall; \
   RCLRBINS="$bin_dir/rClrMono.dll $bin_dir/rClrMono.exp $bin_dir/rClrMono.lib $bin_dir/rClrMono.pdb" ; \
   if [ "False" = "True" ] ; then cmd /c win_cp.cmd $RCLRBINS ../inst/libs/i386/ ; fi ;
   cmd /c win_cp.cmd ./ClrFacade/bin/Release/netstandard2.0/ ../inst/libs/ ClrFacade.*
   
   	    New File  		    7767	C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\bin\Release\netstandard2.0\ClrFacade.deps.json
     0%  
   100%  
   	    New File  		   83456	C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\bin\Release\netstandard2.0\ClrFacade.dll
   100%  
   	    New File  		     378	C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\bin\Release\netstandard2.0\ClrFacade.dll.config
   100%  
   	    New File  		   32832	C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\bin\Release\netstandard2.0\ClrFacade.pdb
   100%  
   cmd /c win_cp.cmd ./ClrFacade/bin/Release/netstandard2.0/ ../inst/libs/ RDotNet.* DynamicInterop.*   
   
   	    New File  		   17920	C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\bin\Release\netstandard2.0\DynamicInterop.dll
     0%  
   100%  
   	    New File  		  130560	C:\Users\tovi85\AppData\Local\Temp\Rtmp4S1KM6\Rbuild74742815906\rClr\src\ClrFacade\bin\Release\netstandard2.0\RDotNet.dll
   100%  
   ** R
   ** inst
   ** byte-compile and prepare package for lazy loading
   ** help
   *** installing help indices
     converting help for package 'rClr'
       finding HTML links ... done
       clrCall                                 html  
       clrCallStatic                           html  
       clrCobj                                 html  
       clrGet                                  html  
       clrGetConstructors                      html  
       clrGetEnumNames                         html  
       clrGetExtPtr                            html  
       clrGetFields                            html  
       clrGetInnerPkgName                      html  
       clrGetLoadedAssemblies                  html  
       clrGetMemberSignature                   html  
       clrGetMethods                           html  
       clrGetNativeLibName                     html  
       clrGetProperties                        html  
       clrGetStaticFields                      html  
       clrGetStaticMemberSignature             html  
       clrGetStaticMembers                     html  
       clrGetStaticMethods                     html  
       clrGetStaticProperties                  html  
       clrGetType                              html  
       clrGetTypesInAssembly                   html  
       clrInit                                 html  
       clrIs                                   html  
       clrLoadAssembly                         html  
       clrNew                                  html  
       clrReflect                              html  
       clrSet                                  html  
       clrSetEnumProperty                      html  
       clrShutdown                             html  
       clrToString                             html  
       clrTraceback                            html  
       clrTypeNameExtPtr                       html  
       clrTypename                             html  
       clrVT                                   html  
       dotOnAttach                             html  
       dotOnLoad                               html  
       getClrVersionString                     html  
       getCurrentConvertedObject               html  
       getNativeLibsPath                       html  
       getSexpType                             html  
       inspectArgs                             html  
       mkClrObjRef                             html  
       peekClrArgs                             html  
       rClr-package                            html  
       rToClrType                              html  
       setClrRefClass                          html  
       setConvertAdvancedTypes                 html  
       setRDotNet                              html  
   ** building package indices
   ** installing vignettes
   ** testing if installed package can be loaded from temporary location
   Error: package or namespace load failed for 'rClr':
    .onLoad failed in loadNamespace() for 'rClr', details:
     call: fun(libname, pkgname)
     error: rClr library .NET framework not found - looked under C:/Users/tovi85/AppData/Local/Temp/Rtmp4S1KM6/Rinst7474233f586e/00LOCK-rClr/00new/rClr/libs//x64 but not found in 
   Error: loading failed
   Execution halted
   ERROR: loading failed
-  removing 'C:/Users/tovi85/AppData/Local/Temp/Rtmp4S1KM6/Rinst7474233f586e/rClr'
         -----------------------------------
   ERROR: package installation failed
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command error

jmp75 commented

Hi,

The message rClr library .NET framework not found is a tad misleading indeed; this is because the native library rClrMs.dll in the package is not found. This is usually because the compilation failed, but there may be an interplay with devtools (devtools has baked in behaviors expecting the presence of a rClr.dll file.

I will see if I can build from the CMD prompt and then see if devtools::build fails.

Hi Jean-Michel,
I tried yesterday to compile from the CMD following the procedure you have given in rClr/README.md. This gave exactly the same error. It was helful to know that the missing item actually is rClrMs.dll and not some version of .NET Framework. I also wonder if the problem is an invalid search path, perphaps constructed during the execution of devtools::build(). Look at the strange path in the error-message:

error: rClr library .NET framework not found - looked under C:/Users/tovi85/AppData/Local/Temp/Rtmp4S1KM6/Rinst7474233f586e/00LOCK-rClr/00new/rClr/libs//x64 but not found in

At least, double slashes is not a valid construct within a path.

I also notice that the search path contains the section .../rClr/libs/x64 while the original src has a similar sequence in the path: rClr/libfiles/x64. Should it be "libfiles" rather than "libs" in the searchpath?

Hi,
I think I found the location where the error message is generated: That happens during the execution of the .onload function in zzz.R. Line 54-56 looks like this:

     if(!(msDll %in% dlls)) {
        stop(paste('rClr library .NET framework not found - looked under', archLibPath, 'but not found in', paste(dlls, collapse=','))) 
      }

I'll investigate this further to see if I can solve the problem.

jmp75 commented

I noticed the build log has C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe as the msbuild.exe used for building. This is likely the cause of failure.

if I launch R CMD build from the windows cmd prompt straight away, the log outputs build cmd line: C:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe rClr.sln //t:Build //p:Configuration=Release //p:Platform=replaced_tgt_platform //consoleloggerparameters:ErrorsOnly and I end up with an outcome similar to yours.

I tried to automagically have the VS msbuild detected but for some reasons the R build process fails to use it; it needs to be set up in the PATH before launching R CMD build rClr_blah.tar.gz or launching R. This is unsatisfying but I just could not find a way to do otherwise.

As mentioned in the readme at https://github.com/rdotnet/rClr , where msbuild from a command prompt (or Sys.which('msbuild') in R) should return first an msbuild from one of the visual studio installation, not the .NET framework one:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

The strange path with 'Temp' folders and double slashes is not surprising; this is what R pkg build does indeed.

Hope this helps