[Rcpp-devel] Shared code in C++ files

Martin Lysy mlysy at uwaterloo.ca
Thu Apr 14 17:33:34 CEST 2016


Dear J.J.,

Thank you very much for the fix.  I can confirm that it works on my
computer.

Would you or Dirk care to weigh in on the appropriate usage of Rcpp for the
project I described in my previous post?  I realize you are both busy, and
thank you both again for the time you've taken to answer my query.

Best regards,

Martin



Martin Lysy
Assistant Professor of Statistics
Department of Statistics and Actuarial Science
University of Waterloo

On Thu, Apr 14, 2016 at 5:36 AM, JJ Allaire <jj.allaire at gmail.com> wrote:

> Happily it was an easy fix!
>
>
> https://github.com/RcppCore/Rcpp/commit/3c096d7ae8523222ac8e83d0e15d92af07df1abe
>
> J.J.
>
> On Thu, Apr 14, 2016 at 5:17 AM, JJ Allaire <jj.allaire at gmail.com> wrote:
>
>> Martin,
>>
>> The code = variation won't work on either platform (as there is no
>> baseline file path from which to compute the location of included files).
>> The file = variation that works on Linux should indeed work on Windows,
>> I'll take a look and see what's going on there.
>>
>> J.J.
>>
>> On Wed, Apr 13, 2016 at 5:15 PM, Martin Lysy <mlysy at uwaterloo.ca> wrote:
>>
>>> In the document "Rcpp Attributes: Rcpp version 0.12.3 as of January 10,
>>> 2016", Section 2.10.2 explains how to share code between C++ files.  I am
>>> obtaining errors when attempting to compile using the outlined steps on
>>> both Windows and Linux.
>>>
>>> Windows:
>>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>> Version: Windows 8.1
>>> R version 3.2.4 Revised (2016-03-16 r70336) -- "Very Secure Dishes"
>>> Rcpp version 0.12.4
>>>
>>> Linux:
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>> Version: CentOS release 6.7 (Final)
>>> R version: 3.2.2 (2015-08-14) -- "Fire Safety"
>>> (I do not have admin privileges to update R on this machine)
>>> Rcpp version: 0.12.4
>>>
>>> Sample code is:
>>>
>>>
>>> #-----------------------------------------------------------------------------------------------
>>>
>>> require(Rcpp)
>>>
>>> # header file
>>> header <- "
>>> #ifndef __UTILITIES__
>>> #define __UTILITIES__
>>> double timesTwo(double x);
>>> #endif // __UTILITIES__
>>> "
>>> cat(header, file = "utilities.hpp")
>>>
>>> # implementation file
>>> impl <- "
>>> #include \"utilities.hpp\"
>>> double timesTwo(double x) {
>>>   return x * 2;
>>> }
>>> "
>>> cat(impl, file = "utilities.cpp")
>>>
>>> # main file
>>> main <- "
>>> #include <Rcpp.h>
>>> using namespace Rcpp;
>>> #include \"utilities.hpp\"
>>> //[[Rcpp::export]]
>>> double TimesTwo(double x) {
>>>   return timesTwo(x);
>>> }
>>> "
>>> cat(main, file = "main.cpp")
>>>
>>> # works on linux
>>> sourceCpp(file = "main.cpp")
>>>
>>> # does not work on linux
>>> sourceCpp(code = main)
>>>
>>>
>>> #-----------------------------------------------------------------------------------------------
>>>
>>> Neither of the last two commands works for me on Windows.  Attached
>>> below is the output of the failed commands for Windows and Linux (first
>>> command for former, second command for latter).  Can you please indicate
>>> what is wrong with the steps above?
>>>
>>> Best regards,
>>>
>>> Martin Lysy
>>> Assistant Professor of Statistics
>>> Department of Statistics and Actuarial Science
>>> University of Waterloo
>>>
>>> ====================================================
>>>
>>> WINDOWS OUTPUT
>>>
>>> > sourceCpp(file = "main.cpp", verbose = TRUE)
>>>
>>> Generated extern "C" functions
>>> --------------------------------------------------------
>>>
>>>
>>> #include <Rcpp.h>
>>> // TimesTwo
>>> double TimesTwo(double x);
>>> RcppExport SEXP sourceCpp_0_TimesTwo(SEXP xSEXP) {
>>> BEGIN_RCPP
>>>     Rcpp::RObject __result;
>>>     Rcpp::RNGScope __rngScope;
>>>     Rcpp::traits::input_parameter< double >::type x(xSEXP);
>>>     __result = Rcpp::wrap(TimesTwo(x));
>>>     return __result;
>>> END_RCPP
>>> }
>>>
>>> Generated R functions
>>> -------------------------------------------------------
>>>
>>> `.sourceCpp_0_DLLInfo` <-
>>> dyn.load('C:/Users/mlysy/AppData/Local/Temp/RtmpclqYkL/sourcecpp_c5c157c5536/sourceCpp_1.dll')
>>>
>>> TimesTwo <- Rcpp:::sourceCppFunction(function(x) {}, FALSE,
>>> `.sourceCpp_0_DLLInfo`, 'sourceCpp_0_TimesTwo')
>>>
>>> rm(`.sourceCpp_0_DLLInfo`)
>>>
>>> Building shared library
>>> --------------------------------------------------------
>>>
>>> DIR: C:/Users/mlysy/AppData/Local/Temp/RtmpclqYkL/sourcecpp_c5c157c5536
>>>
>>> c:/PROGRA~1/R/R-32~1.4RE/bin/x64/R CMD SHLIB -o "sourceCpp_1.dll"
>>> "c:\Users\Jerome\Documents\R\test\utilities.cpp" "main.cpp"
>>> make: *** No rule to make target
>>> `c:\Users\Jerome\Documents\R\test\utilities.o', needed by
>>> `sourceCpp_1.dll'.  Stop.
>>> Warning message:
>>> running command 'make -f "c:/PROGRA~1/R/R-32~1.4RE/etc/x64/Makeconf" -f
>>> "c:/PROGRA~1/R/R-32~1.4RE/share/make/winshlib.mk" -f
>>> "C:\Users\mlysy\AppData\Roaming/.R/Makevars"
>>> SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)'
>>> SHLIB="sourceCpp_1.dll" WIN=64 TCLBIN=64
>>> OBJECTS="c:\Users\Jerome\Documents\R\test\utilities.o main.o"' had status 2
>>> Error in sourceCpp(file = "main.cpp", verbose = TRUE) :
>>>   Error 1 occurred building shared library.
>>>
>>> ==============================================================
>>>
>>> LINUX OUTPUT
>>>
>>> > sourceCpp(code = main, verbose = TRUE)
>>>
>>> Generated extern "C" functions
>>> --------------------------------------------------------
>>>
>>>
>>> #include <Rcpp.h>
>>> // TimesTwo
>>> double TimesTwo(double x);
>>> RcppExport SEXP sourceCpp_0_TimesTwo(SEXP xSEXP) {
>>> BEGIN_RCPP
>>>     Rcpp::RObject __result;
>>>     Rcpp::RNGScope __rngScope;
>>>     Rcpp::traits::input_parameter< double >::type x(xSEXP);
>>>     __result = Rcpp::wrap(TimesTwo(x));
>>>     return __result;
>>> END_RCPP
>>> }
>>>
>>> Generated R functions
>>> -------------------------------------------------------
>>>
>>> `.sourceCpp_0_DLLInfo` <-
>>> dyn.load('/tmp/RtmpEhyQ33/sourcecpp_7c167caa37d5/sourceCpp_1.so')
>>>
>>> TimesTwo <- Rcpp:::sourceCppFunction(function(x) {}, FALSE,
>>> `.sourceCpp_0_DLLInfo`, 'sourceCpp_0_TimesTwo')
>>>
>>> rm(`.sourceCpp_0_DLLInfo`)
>>>
>>> Building shared library
>>> --------------------------------------------------------
>>>
>>> DIR: /tmp/RtmpEhyQ33/sourcecpp_7c167caa37d5
>>>
>>> /software/r-3.2.2-tcl86/distribution/lib64/R/bin/R CMD SHLIB -o
>>> 'sourceCpp_1.so'  'file7c16504c2103.cpp'
>>> g++ -I/software/r-3.2.2-tcl86/distribution/lib64/R/include -DNDEBUG
>>> -I/software/readline/include -I/software/gsl-1.15/include
>>> -I"/fsys1/.software/arch/r-3.2.2-tcl86/distribution/lib64/R-contrib/Rcpp/include"
>>> -I"/tmp/RtmpEhyQ33"    -fpic  -g -O2  -c file7c16504c2103.cpp -o
>>> file7c16504c2103.o
>>> file7c16504c2103.cpp:4:25: error: utilities.hpp: No such file or
>>> directory
>>> file7c16504c2103.cpp: In function 'double TimesTwo(double)':
>>> file7c16504c2103.cpp:7: error: 'timesTwo' was not declared in this scope
>>> make: *** [file7c16504c2103.o] Error 1
>>> Error in sourceCpp(code = main, verbose = TRUE) :
>>>   Error 1 occurred building shared library.
>>>
>>>
>>> _______________________________________________
>>> Rcpp-devel mailing list
>>> Rcpp-devel at lists.r-forge.r-project.org
>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20160414/ccd2719c/attachment.html>


More information about the Rcpp-devel mailing list