0

THIS QUESTION PERTAINS TO WINDOWS 10. There is a similar question but that does not answer or resolve the issue that I am facing.

I have a C++ function written and am using sourceCpp to compile. I have specified a directory location so I know where the modified code lives. I am looking at the verbose output for the linking process. This is what it looks like.

I am trying to get a Debug build. Looks like windowsDebugDLL=TRUE has no effect. I am running on Windows 10. What gets generated is optimized code.

Also, I would like to know what library -lR links to. I have searched for libR.lib, libR.a. R.lib, R.a to no avail.

Where is the R makefile located that is used to do the compilation? Is it just temporarily generated and erased?

Where is the Makevars file on Windows. Putting it under .R folder under Users/ directory does not do it. Makevars.win does not do it either? So the question is... is it possible to create a debug version of the dll at all?

Thanks in advance for all the responses.

Rcpp::sourceCpp("sfgkanal.cpp", verbose=TRUE, rebuild=FALSE, cacheDir = getwd(), windowsDebugDLL=TRUE)
    Generated extern "C" functions 
--------------------------------------------------------


#include <Rcpp.h>
#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>&  Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// analyseSFGK
Rcpp::List analyseSFGK(Rcpp::List& x);
RcppExport SEXP sourceCpp_1_analyseSFGK(SEXP xSEXP) {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    Rcpp::traits::input_parameter< Rcpp::List& >::type x(xSEXP);
    rcpp_result_gen = Rcpp::wrap(analyseSFGK(x));
    return rcpp_result_gen;
END_RCPP
}
// libraryReady
Rcpp::String libraryReady();
RcppExport SEXP sourceCpp_1_libraryReady() {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    rcpp_result_gen = Rcpp::wrap(libraryReady());
    return rcpp_result_gen;
END_RCPP
}

Generated R functions 
-------------------------------------------------------

`.sourceCpp_1_DLLInfo` <- dyn.load('H:/jupyter-mktmicro-research/R/sfgk/sourceCpp-x86_64-w64-mingw32-1.0.9/sourcecpp_69f04dc58d9/sourceCpp_19.dll')

analyseSFGK <- Rcpp:::sourceCppFunction(function(x) {}, FALSE, `.sourceCpp_1_DLLInfo`, 'sourceCpp_1_analyseSFGK')
libraryReady <- Rcpp:::sourceCppFunction(function() {}, FALSE, `.sourceCpp_1_DLLInfo`, 'sourceCpp_1_libraryReady')

rm(`.sourceCpp_1_DLLInfo`)

Building shared library
--------------------------------------------------------

DIR: H:/jupyter-mktmicro-research/R/sfgk/sourceCpp-x86_64-w64-mingw32-1.0.9/sourcecpp_69f04dc58d9

C:/PROGRA~1/R/R-42~1.0/bin/x64/R CMD SHLIB -d --preclean -o "sourceCpp_19.dll" "sfgkanal.cpp" 
g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-42~1.0/include" -DNDEBUG   -I"C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include" -I"H:/jupyter-mktmicro-research/R/sfgk"   -I"C:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign  -c sfgkanal.cpp -o sfgkanal.o
In file included from C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp/Vector.h:54,
                 from C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp.h:40,
                 from sfgkanal.cpp:1:
C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp/vector/traits.h: In lambda function:
C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp/vector/traits.h:49:47: warning: '*((void*)(&<anonymous>)+16).Rcpp::traits::r_vector_cache<13, Rcpp::PreserveStorage>::start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   inline proxy ref(R_xlen_t i) const { return start[i] ; }
      |                                               ^~~~~
C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp/vector/traits.h:49:47: warning: '*((void*)(&<anonymous>)+16).Rcpp::traits::r_vector_cache<13, Rcpp::PreserveStorage>::start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   inline proxy ref(R_xlen_t i) const { return start[i] ; }
      |                                               ^~~~~
C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp/vector/traits.h:49:47: warning: '*((void*)(&<anonymous>)+16).Rcpp::traits::r_vector_cache<13, Rcpp::PreserveStorage>::start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   inline proxy ref(R_xlen_t i) const { return start[i] ; }
      |                                               ^~~~~
C:/Users/.../AppData/Local/R/win-library/4.2/Rcpp/include/Rcpp/vector/traits.h:49:47: warning: '*((void*)(&<anonymous>)+16).Rcpp::traits::r_vector_cache<13, Rcpp::PreserveStorage>::start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   inline proxy ref(R_xlen_t i) const { return start[i] ; }
      |                                               ^~~~~
g++ -std=gnu++11 -shared -static-libgcc -o sourceCpp_19.dll tmp.def sfgkanal.o -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.0/bin/x64 -lR
Ramesh Kadambi
  • 546
  • 6
  • 17
  • Sounds like you are trying this from Visual Studio or VS Code or ... If so, then (in short) "just don't". See the Rcpp FAQ, and the various 'how do I build an R package' tutorials. – Dirk Eddelbuettel Sep 08 '22 at 11:34
  • @DirkEddelbuettel l am trying this from RStudio and R command line version. I want to be able to debug the code I wrote. I presume that should be possible to do from Visual Studio. BTW. what is the link library that R uses? In order to debug I am just attaching to the R process and stepping into the code. So presumably that should be possible. – Ramesh Kadambi Sep 08 '22 at 22:04
  • @DirkEddelbuettel The issue I am having is that it always produces optimized version of the DLL. – Ramesh Kadambi Sep 08 '22 at 22:06
  • We ship Rcpp with ten (10) pdf vignettes because there is a _lot_ to document. Rather than going through all of this here, could I ask you to take a look at [A Brief Introduction to Rcpp](https://cloud.r-project.org/web/packages/Rcpp/vignettes/Rcpp-introduction) ? – Dirk Eddelbuettel Sep 08 '22 at 22:07
  • @DirkEddelbuettel I will check it out and see what it reveals. I have the book "Seamless Integration with Rcpp", that was not very useful. – Ramesh Kadambi Sep 08 '22 at 22:12
  • I have this code written that I am trying to debug is all... – Ramesh Kadambi Sep 08 '22 at 22:15
  • Rcpp is an R package. It behaves like any other R package, and how to manage those is describe in manuals _Writing R Extension_ and _R Administration + Installation_ which you can see in many places, one of them [here](https://rstudio.github.io/r-manuals/). In short, the optimization is NOT something Rcpp as a package controls. You can, as admin of your machine / your compilation. See about `~/.R/Makevars`. Good luck. – Dirk Eddelbuettel Sep 08 '22 at 22:17
  • @DirkEddelBuettl Thank you that helps. On windows where does it go? I understand that it is not Rcpp thing. This was more of an R question, and I was hoping that Rcpp folks would answer as well. – Ramesh Kadambi Sep 08 '22 at 22:24
  • @DirkEddelbuettel So the recommended debugger on windows is GDB as well? Is that the moral of the story? – Ramesh Kadambi Sep 08 '22 at 22:43
  • @DirkEddelbuettel apologies to bug you, is there a pretty print of RCPP stuff for gdb? – Ramesh Kadambi Sep 08 '22 at 23:13
  • No, debugging is hard. On all OSs. No shortcuts. But again, _not one of your questions pertained to Rcpp_ and you are asking _generic 'how do I do X with R on Windows_ questions. – Dirk Eddelbuettel Sep 08 '22 at 23:16
  • @DirkEddelbuettel I am not sure what you mean by not one of your questions pertained to Rcpp? I am asking how you get a debug version of the library using Rcpp::sourceCpp. The windowsDebugDll = TRUE does not do it. That is how the code is compiled is it not? Is that a Rcpp question, R question how does it matter? At the end of the day R CMD SHLIB is called, and the question was how do you configure this? – Ramesh Kadambi Sep 13 '22 at 09:19
  • How an Rcpp package is built and compiled is _entirely_ driven by how R compiles a package, Rcpp just calls into it. As such you are better off with an R question to a broader R audience. – Dirk Eddelbuettel Sep 13 '22 at 10:14
  • This has been tagged to the broader R group as well. – Ramesh Kadambi Sep 16 '22 at 09:06

0 Answers0