Hello, I employ a variant of the following lines in a cygwin bash session in Windows XP to compile my .cpp file. $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"` $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"` $ R CMD SHLIB fastLm.cpp I receive the following compile error: G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o fastLm.o G++:Rscript.exe: No such file or directory fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory fastLm.cpp:2: error: 'SEXP' does not have name a type I've included the R bin directory containing Rscript.exe to the PATH environment statement. Should one use a different syntax for windows to capture RcppArmadillo dependencies? (Fyi, I am able to build using inline, though my code is 600 lines and I will have multiple versions, so using the old approach may provide the most modular de-bugging approach vs. re-installing a package as I add files). Thanks, Terrance Savitsky __________________________________________________________________________ This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101211/ec1136ac/attachment.htm>
[Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
14 messages · Romain Francois, Savitsky, Terrance, Dirk Eddelbuettel
Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
Hello, I employ a variant of the following lines in a cygwin bash session in Windows XP to compile my .cpp file. $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"` $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"` $ R CMD SHLIB fastLm.cpp I receive the following compile error: G++ -I?C:/PROGRA~1/R/R-212~1.0/include? Rscript.exe ?e ?RcppArmadillo:::CxxxFlags()? ?O2 ? Wall ?pedantic ? c fastLm.cpp ? o fastLm.o G++:Rscript.exe: No such file or directory fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory fastLm.cpp:2: error: ?SEXP? does not have name a type I?ve included the R bin directory containing Rscript.exe to the PATH environment statement. Should one use a different syntax for windows to capture RcppArmadillo dependencies? (Fyi, I am able to build using inline, though my code is 600 lines and I will have multiple versions, so using the old approach may provide the most modular de-bugging approach vs. re-installing a package as I add files). Thanks, Terrance Savitsky
Hello,
I would strongly advise you to make it a package, especially if you deal
with multiple files, etc ...
One thing you might want to consider is to use the verbose argument of
cxxfunction, so that inline shows you how it runs the show.
For example:
require(RcppArmadillo)
require(inline)
f <- cxxfunction( , '
arma::mat x(2,2) ;
NumericMatrix res = wrap( x + x ) ;
return res ;
', plugin = "RcppArmadillo", verbose = TRUE )
When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
For example, it shows me this on OSX:
romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
Le chargement a n?cessit? le package : RcppArmadillo
Le chargement a n?cessit? le package : Rcpp
Le chargement a n?cessit? le package : methods
Le chargement a n?cessit? le package : inline
>> setting environment variables:
PKG_LIBS =
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
>> LinkingTo : RcppArmadillo, Rcpp
CLINK_CPPFLAGS =
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
>> Program source :
1 :
2 : // includes from the plugin
3 : #include <RcppArmadillo.h>
4 : #include <Rcpp.h>
5 :
6 :
7 : #ifndef BEGIN_RCPP
8 : #define BEGIN_RCPP
9 : #endif
10 :
11 : #ifndef END_RCPP
12 : #define END_RCPP
13 : #endif
14 :
15 : using namespace Rcpp;
16 :
17 :
18 : // user includes
19 :
20 :
21 : // declarations
22 : extern "C" {
23 : SEXP file313a14a1( ) ;
24 : }
25 :
26 : // definition
27 :
28 : SEXP file313a14a1( ){
29 : BEGIN_RCPP
30 :
31 : arma::mat x(2,2) ;
32 : NumericMatrix res = wrap( x + x ) ;
33 : return res ;
34 :
35 : END_RCPP
36 : }
37 :
38 :
Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
file313a14a1.cpp 2> file313a14a1.cpp.err.txt
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64
-I/usr/local/include
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
-fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -o file313a14a1.so file313a14a1.o
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
-lgfortran -F/Library/Frameworks/R.framework/.. -framework R
-Wl,-framework -Wl,CoreFoundation
Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
PKG_CPPFLAGS if you prefer).
Another tip with inline is that you can read the code from a file, e.g :
f <- cxxfunction( ,
paste( readLines("bla.cpp"), collapse = "\n") ,
plugin = "RcppArmadillo", verbose = TRUE )
This way you can import multiple files, etc ... while keeping the C++
code out of the R code. I would still however very strongly recommend
you to make a package. It is well documented, easy and it will save you
some time.
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/fT2rZM : highlight 0.2-5 |- http://bit.ly/gpCSpH : Evolution of Rcpp code size `- http://bit.ly/hovakS : RcppGSL initial release
Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
Hello, I employ a variant of the following lines in a cygwin bash session in Windows XP to compile my .cpp file. $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"` $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"` $ R CMD SHLIB fastLm.cpp I receive the following compile error: G++ -I?C:/PROGRA~1/R/R-212~1.0/include? Rscript.exe ?e ?RcppArmadillo:::CxxxFlags()? ?O2 ? Wall ?pedantic ? c fastLm.cpp ? o fastLm.o G++:Rscript.exe: No such file or directory fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory fastLm.cpp:2: error: ?SEXP? does not have name a type I?ve included the R bin directory containing Rscript.exe to the PATH environment statement. Should one use a different syntax for windows to capture RcppArmadillo dependencies? (Fyi, I am able to build using inline, though my code is 600 lines and I will have multiple versions, so using the old approach may provide the most modular de-bugging approach vs. re-installing a package as I add files). Thanks, Terrance Savitsky
Another way that is close to what you want to do (but still, please
follow my previous advice) is to use R's abilities instead of windows:
Consider this simple bla.cpp file :
#include <RcppArmadillo.h>
using namespace Rcpp ;
extern "C" SEXP foo(){
arma::mat x(2,2) ;
NumericMatrix res = wrap( x + x ) ;
return res ;
}
You could R CMD SHLIB it using this little R script (compile.R):
require(RcppArmadillo)
PKG_LIBS <- sprintf( "%s $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)",
Rcpp:::RcppLdFlags() )
PKG_CPPFLAGS <- sprintf( "%s %s", Rcpp:::RcppCxxFlags(),
RcppArmadillo:::RcppArmadilloCxxFlags() )
Sys.setenv(
PKG_LIBS = PKG_LIBS ,
PKG_CPPFLAGS = PKG_CPPFLAGS
)
R <- file.path( R.home(component = "bin"), "R" )
system( sprintf( "%s CMD SHLIB %s", R, paste( commandArgs(TRUE),
collapse = " ") ) )
Then you do:
romain at naxos /tmp $ Rscript compile.R bla.cpp
Le chargement a n?cessit? le package : RcppArmadillo
Le chargement a n?cessit? le package : Rcpp
Le chargement a n?cessit? le package : methods
Le chargement a n?cessit? le package : inline
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64
-I/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
-I/usr/local/include -fPIC -g -O3 -Wall -pipe -c bla.cpp -o bla.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -o bla.so bla.o
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
-lgfortran -F/Library/Frameworks/R.framework/.. -framework R
-Wl,-framework -Wl,CoreFoundation
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/fT2rZM : highlight 0.2-5 |- http://bit.ly/gpCSpH : Evolution of Rcpp code size `- http://bit.ly/hovakS : RcppGSL initial release
Based on this, I've added Rcpp:::SHLIB and RcppArmadillo:::SHLIB, so
that with the next versions of these packages, you can do:
$ Rscript -e "RcppArmadillo:::SHLIB('bla.cpp')"
Romain
Le 12/12/10 13:15, Romain Francois a ?crit :
Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
Hello, I employ a variant of the following lines in a cygwin bash session in Windows XP to compile my .cpp file. $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"` $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"` $ R CMD SHLIB fastLm.cpp I receive the following compile error: G++ -I?C:/PROGRA~1/R/R-212~1.0/include? Rscript.exe ?e ?RcppArmadillo:::CxxxFlags()? ?O2 ? Wall ?pedantic ? c fastLm.cpp ? o fastLm.o G++:Rscript.exe: No such file or directory fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory fastLm.cpp:2: error: ?SEXP? does not have name a type I?ve included the R bin directory containing Rscript.exe to the PATH environment statement. Should one use a different syntax for windows to capture RcppArmadillo dependencies? (Fyi, I am able to build using inline, though my code is 600 lines and I will have multiple versions, so using the old approach may provide the most modular de-bugging approach vs. re-installing a package as I add files). Thanks, Terrance Savitsky
Another way that is close to what you want to do (but still, please
follow my previous advice) is to use R's abilities instead of windows:
Consider this simple bla.cpp file :
#include <RcppArmadillo.h>
using namespace Rcpp ;
extern "C" SEXP foo(){
arma::mat x(2,2) ;
NumericMatrix res = wrap( x + x ) ;
return res ;
}
You could R CMD SHLIB it using this little R script (compile.R):
require(RcppArmadillo)
PKG_LIBS <- sprintf( "%s $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)",
Rcpp:::RcppLdFlags() )
PKG_CPPFLAGS <- sprintf( "%s %s", Rcpp:::RcppCxxFlags(),
RcppArmadillo:::RcppArmadilloCxxFlags() )
Sys.setenv(
PKG_LIBS = PKG_LIBS ,
PKG_CPPFLAGS = PKG_CPPFLAGS
)
R <- file.path( R.home(component = "bin"), "R" )
system( sprintf( "%s CMD SHLIB %s", R, paste( commandArgs(TRUE),
collapse = " ") ) )
Then you do:
romain at naxos /tmp $ Rscript compile.R bla.cpp
Le chargement a n?cessit? le package : RcppArmadillo
Le chargement a n?cessit? le package : Rcpp
Le chargement a n?cessit? le package : methods
Le chargement a n?cessit? le package : inline
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64
-I/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
-I/usr/local/include -fPIC -g -O3 -Wall -pipe -c bla.cpp -o bla.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -o bla.so bla.o
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
-lgfortran -F/Library/Frameworks/R.framework/.. -framework R
-Wl,-framework -Wl,CoreFoundation
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/fT2rZM : highlight 0.2-5 |- http://bit.ly/gpCSpH : Evolution of Rcpp code size `- http://bit.ly/hovakS : RcppGSL initial release
1 day later
Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer. Thanks, Terrance Savitsky -----Original Message----- From: Romain Francois [mailto:romain at r-enthusiasts.com] Sent: Sunday, December 12, 2010 3:58 AM To: Savitsky, Terrance Cc: rcpp-devel at r-forge.wu-wien.ac.at Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
Hello, I employ a variant of the following lines in a cygwin bash session in Windows XP to compile my .cpp file. $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"` $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"` $ R CMD SHLIB fastLm.cpp I receive the following compile error: G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o fastLm.o G++:Rscript.exe: No such file or directory fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory fastLm.cpp:2: error: 'SEXP' does not have name a type I've included the R bin directory containing Rscript.exe to the PATH environment statement. Should one use a different syntax for windows to capture RcppArmadillo dependencies? (Fyi, I am able to build using inline, though my code is 600 lines and I will have multiple versions, so using the old approach may provide the most modular de-bugging approach vs. re-installing a package as I add files). Thanks, Terrance Savitsky
Hello,
I would strongly advise you to make it a package, especially if you deal
with multiple files, etc ...
One thing you might want to consider is to use the verbose argument of
cxxfunction, so that inline shows you how it runs the show.
For example:
require(RcppArmadillo)
require(inline)
f <- cxxfunction( , '
arma::mat x(2,2) ;
NumericMatrix res = wrap( x + x ) ;
return res ;
', plugin = "RcppArmadillo", verbose = TRUE )
When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
For example, it shows me this on OSX:
romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
Le chargement a n?cessit? le package : RcppArmadillo
Le chargement a n?cessit? le package : Rcpp
Le chargement a n?cessit? le package : methods
Le chargement a n?cessit? le package : inline
>> setting environment variables:
PKG_LIBS =
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
>> LinkingTo : RcppArmadillo, Rcpp
CLINK_CPPFLAGS =
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
>> Program source :
1 :
2 : // includes from the plugin
3 : #include <RcppArmadillo.h>
4 : #include <Rcpp.h>
5 :
6 :
7 : #ifndef BEGIN_RCPP
8 : #define BEGIN_RCPP
9 : #endif
10 :
11 : #ifndef END_RCPP
12 : #define END_RCPP
13 : #endif
14 :
15 : using namespace Rcpp;
16 :
17 :
18 : // user includes
19 :
20 :
21 : // declarations
22 : extern "C" {
23 : SEXP file313a14a1( ) ;
24 : }
25 :
26 : // definition
27 :
28 : SEXP file313a14a1( ){
29 : BEGIN_RCPP
30 :
31 : arma::mat x(2,2) ;
32 : NumericMatrix res = wrap( x + x ) ;
33 : return res ;
34 :
35 : END_RCPP
36 : }
37 :
38 :
Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
file313a14a1.cpp 2> file313a14a1.cpp.err.txt
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64
-I/usr/local/include
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
-fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -o file313a14a1.so file313a14a1.o
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
-lgfortran -F/Library/Frameworks/R.framework/.. -framework R
-Wl,-framework -Wl,CoreFoundation
Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
PKG_CPPFLAGS if you prefer).
Another tip with inline is that you can read the code from a file, e.g :
f <- cxxfunction( ,
paste( readLines("bla.cpp"), collapse = "\n") ,
plugin = "RcppArmadillo", verbose = TRUE )
This way you can import multiple files, etc ... while keeping the C++
code out of the R code. I would still however very strongly recommend
you to make a package. It is well documented, easy and it will save you
some time.
Romain
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/fT2rZM : highlight 0.2-5 |- http://bit.ly/gpCSpH : Evolution of Rcpp code size `- http://bit.ly/hovakS : RcppGSL initial release __________________________________________________________________________ This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
snprintf is defined in the cstdio header.
Dirk
|
| Thanks, Terrance Savitsky
|
| -----Original Message-----
| From: Romain Francois [mailto:romain at r-enthusiasts.com]
| Sent: Sunday, December 12, 2010 3:58 AM
| To: Savitsky, Terrance
| Cc: rcpp-devel at r-forge.wu-wien.ac.at
| Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
|
| Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| > Hello,
| >
| > I employ a variant of the following lines in a cygwin bash session in
| > Windows XP to compile my .cpp file.
| >
| > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| >
| > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| >
| > $ R CMD SHLIB fastLm.cpp
| >
| > I receive the following compile error:
| >
| > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| > fastLm.o
| >
| > G++:Rscript.exe: No such file or directory
| >
| > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| >
| > fastLm.cpp:2: error: 'SEXP' does not have name a type
| >
| > I've included the R bin directory containing Rscript.exe to the PATH
| > environment statement. Should one use a different syntax for windows to
| > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| > inline, though my code is 600 lines and I will have multiple versions,
| > so using the old approach may provide the most modular de-bugging
| > approach vs. re-installing a package as I add files).
| >
| > Thanks, Terrance Savitsky
|
| Hello,
|
| I would strongly advise you to make it a package, especially if you deal
| with multiple files, etc ...
|
| One thing you might want to consider is to use the verbose argument of
| cxxfunction, so that inline shows you how it runs the show.
|
| For example:
|
| require(RcppArmadillo)
| require(inline)
|
| f <- cxxfunction( , '
| arma::mat x(2,2) ;
| NumericMatrix res = wrap( x + x ) ;
| return res ;
| ', plugin = "RcppArmadillo", verbose = TRUE )
|
| When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
|
| For example, it shows me this on OSX:
|
| romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| Le chargement a n?cessit? le package : RcppArmadillo
| Le chargement a n?cessit? le package : Rcpp
| Le chargement a n?cessit? le package : methods
| Le chargement a n?cessit? le package : inline
| >> setting environment variables:
| PKG_LIBS =
| /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
|
| >> LinkingTo : RcppArmadillo, Rcpp
| CLINK_CPPFLAGS =
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
|
|
| >> Program source :
|
| 1 :
| 2 : // includes from the plugin
| 3 : #include <RcppArmadillo.h>
| 4 : #include <Rcpp.h>
| 5 :
| 6 :
| 7 : #ifndef BEGIN_RCPP
| 8 : #define BEGIN_RCPP
| 9 : #endif
| 10 :
| 11 : #ifndef END_RCPP
| 12 : #define END_RCPP
| 13 : #endif
| 14 :
| 15 : using namespace Rcpp;
| 16 :
| 17 :
| 18 : // user includes
| 19 :
| 20 :
| 21 : // declarations
| 22 : extern "C" {
| 23 : SEXP file313a14a1( ) ;
| 24 : }
| 25 :
| 26 : // definition
| 27 :
| 28 : SEXP file313a14a1( ){
| 29 : BEGIN_RCPP
| 30 :
| 31 : arma::mat x(2,2) ;
| 32 : NumericMatrix res = wrap( x + x ) ;
| 33 : return res ;
| 34 :
| 35 : END_RCPP
| 36 : }
| 37 :
| 38 :
| Compilation argument:
| /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| -I/Library/Frameworks/R.framework/Resources/include/x86_64
| -I/usr/local/include
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| dynamic_lookup -single_module -multiply_defined suppress
| -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| -Wl,-framework -Wl,CoreFoundation
|
| Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| PKG_CPPFLAGS if you prefer).
|
|
|
| Another tip with inline is that you can read the code from a file, e.g :
|
| f <- cxxfunction( ,
| paste( readLines("bla.cpp"), collapse = "\n") ,
| plugin = "RcppArmadillo", verbose = TRUE )
|
| This way you can import multiple files, etc ... while keeping the C++
| code out of the R code. I would still however very strongly recommend
| you to make a package. It is well documented, easy and it will save you
| some time.
|
| Romain
|
| --
| Romain Francois
| Professional R Enthusiast
| +33(0) 6 28 91 30 30
| http://romainfrancois.blog.free.fr
| |- http://bit.ly/fT2rZM : highlight 0.2-5
| |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| `- http://bit.ly/hovakS : RcppGSL initial release
|
|
|
| __________________________________________________________________________
|
| This email message is for the sole use of the intended recipient(s) and
| may contain confidential information. Any unauthorized review, use,
| disclosure or distribution is prohibited. If you are not the intended
| recipient, please contact the sender by reply email and destroy all copies
| of the original message.
|
| _______________________________________________
| 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
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
This header is not in the helpful examples, nor in the simple 'bla.cpp' Romain crafted that employed RcppArmadillo. Is the requirement for me to add this header related to the Windows version of Rcpp or is it universal and obvious to a C++ developer? Thanks. Terrance -----Original Message----- From: Dirk Eddelbuettel [mailto:edd at debian.org] Sent: Tuesday, December 14, 2010 7:56 AM To: Savitsky, Terrance Cc: rcpp-devel at r-forge.wu-wien.ac.at Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP
On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
snprintf is defined in the cstdio header.
Dirk
|
| Thanks, Terrance Savitsky
|
| -----Original Message-----
| From: Romain Francois [mailto:romain at r-enthusiasts.com]
| Sent: Sunday, December 12, 2010 3:58 AM
| To: Savitsky, Terrance
| Cc: rcpp-devel at r-forge.wu-wien.ac.at
| Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
|
| Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| > Hello,
| >
| > I employ a variant of the following lines in a cygwin bash session in
| > Windows XP to compile my .cpp file.
| >
| > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| >
| > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| >
| > $ R CMD SHLIB fastLm.cpp
| >
| > I receive the following compile error:
| >
| > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| > fastLm.o
| >
| > G++:Rscript.exe: No such file or directory
| >
| > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| >
| > fastLm.cpp:2: error: 'SEXP' does not have name a type
| >
| > I've included the R bin directory containing Rscript.exe to the PATH
| > environment statement. Should one use a different syntax for windows to
| > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| > inline, though my code is 600 lines and I will have multiple versions,
| > so using the old approach may provide the most modular de-bugging
| > approach vs. re-installing a package as I add files).
| >
| > Thanks, Terrance Savitsky
|
| Hello,
|
| I would strongly advise you to make it a package, especially if you deal
| with multiple files, etc ...
|
| One thing you might want to consider is to use the verbose argument of
| cxxfunction, so that inline shows you how it runs the show.
|
| For example:
|
| require(RcppArmadillo)
| require(inline)
|
| f <- cxxfunction( , '
| arma::mat x(2,2) ;
| NumericMatrix res = wrap( x + x ) ;
| return res ;
| ', plugin = "RcppArmadillo", verbose = TRUE )
|
| When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
|
| For example, it shows me this on OSX:
|
| romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| Le chargement a n?cessit? le package : RcppArmadillo
| Le chargement a n?cessit? le package : Rcpp
| Le chargement a n?cessit? le package : methods
| Le chargement a n?cessit? le package : inline
| >> setting environment variables:
| PKG_LIBS =
| /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
|
| >> LinkingTo : RcppArmadillo, Rcpp
| CLINK_CPPFLAGS =
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
|
|
| >> Program source :
|
| 1 :
| 2 : // includes from the plugin
| 3 : #include <RcppArmadillo.h>
| 4 : #include <Rcpp.h>
| 5 :
| 6 :
| 7 : #ifndef BEGIN_RCPP
| 8 : #define BEGIN_RCPP
| 9 : #endif
| 10 :
| 11 : #ifndef END_RCPP
| 12 : #define END_RCPP
| 13 : #endif
| 14 :
| 15 : using namespace Rcpp;
| 16 :
| 17 :
| 18 : // user includes
| 19 :
| 20 :
| 21 : // declarations
| 22 : extern "C" {
| 23 : SEXP file313a14a1( ) ;
| 24 : }
| 25 :
| 26 : // definition
| 27 :
| 28 : SEXP file313a14a1( ){
| 29 : BEGIN_RCPP
| 30 :
| 31 : arma::mat x(2,2) ;
| 32 : NumericMatrix res = wrap( x + x ) ;
| 33 : return res ;
| 34 :
| 35 : END_RCPP
| 36 : }
| 37 :
| 38 :
| Compilation argument:
| /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| -I/Library/Frameworks/R.framework/Resources/include/x86_64
| -I/usr/local/include
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| dynamic_lookup -single_module -multiply_defined suppress
| -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| -Wl,-framework -Wl,CoreFoundation
|
| Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| PKG_CPPFLAGS if you prefer).
|
|
|
| Another tip with inline is that you can read the code from a file, e.g :
|
| f <- cxxfunction( ,
| paste( readLines("bla.cpp"), collapse = "\n") ,
| plugin = "RcppArmadillo", verbose = TRUE )
|
| This way you can import multiple files, etc ... while keeping the C++
| code out of the R code. I would still however very strongly recommend
| you to make a package. It is well documented, easy and it will save you
| some time.
|
| Romain
|
| --
| Romain Francois
| Professional R Enthusiast
| +33(0) 6 28 91 30 30
| http://romainfrancois.blog.free.fr
| |- http://bit.ly/fT2rZM : highlight 0.2-5
| |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| `- http://bit.ly/hovakS : RcppGSL initial release
|
|
|
| __________________________________________________________________________
|
| This email message is for the sole use of the intended recipient(s) and
| may contain confidential information. Any unauthorized review, use,
| disclosure or distribution is prohibited. If you are not the intended
| recipient, please contact the sender by reply email and destroy all copies
| of the original message.
|
| _______________________________________________
| 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
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
I should've checked before replying; this solution (including cstdio header) doesn't work. Where the 'snprintf' error appears is after the following: C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format-Wrap.hpp: error: 'snprintf' is not a member of 'std'. Stepping back, I view your terrific work as focused to reduce the coding overhead / technical burden of coding in C++ for R, given that the primary reason for such work is to improve run speed and not to introduce new functionality. This work could ultimately evolve into a backdoor compiled version of R what with the smooth sugar-based syntax. I make this point because that's why I'm hueing closely to the examples; I assume that the headers and namespaces that you include also scoop up the common C++ headers and namespaces. So I'm working to understand the by-design most productive way to build code in RcppArmadillo for package release. Then, back to my original question, using the bla.cpp of Romain, does this problem not duplicate under Debian Linux or OS X? Is it a Windows problem - somehow a reference from within RcppArmadillo.h not working under the Rtools toolchain? Thanks. -----Original Message----- From: Dirk Eddelbuettel [mailto:edd at debian.org] Sent: Tuesday, December 14, 2010 7:56 AM To: Savitsky, Terrance Cc: rcpp-devel at r-forge.wu-wien.ac.at Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP
On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
snprintf is defined in the cstdio header.
Dirk
|
| Thanks, Terrance Savitsky
|
| -----Original Message-----
| From: Romain Francois [mailto:romain at r-enthusiasts.com]
| Sent: Sunday, December 12, 2010 3:58 AM
| To: Savitsky, Terrance
| Cc: rcpp-devel at r-forge.wu-wien.ac.at
| Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
|
| Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| > Hello,
| >
| > I employ a variant of the following lines in a cygwin bash session in
| > Windows XP to compile my .cpp file.
| >
| > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| >
| > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| >
| > $ R CMD SHLIB fastLm.cpp
| >
| > I receive the following compile error:
| >
| > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| > fastLm.o
| >
| > G++:Rscript.exe: No such file or directory
| >
| > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| >
| > fastLm.cpp:2: error: 'SEXP' does not have name a type
| >
| > I've included the R bin directory containing Rscript.exe to the PATH
| > environment statement. Should one use a different syntax for windows to
| > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| > inline, though my code is 600 lines and I will have multiple versions,
| > so using the old approach may provide the most modular de-bugging
| > approach vs. re-installing a package as I add files).
| >
| > Thanks, Terrance Savitsky
|
| Hello,
|
| I would strongly advise you to make it a package, especially if you deal
| with multiple files, etc ...
|
| One thing you might want to consider is to use the verbose argument of
| cxxfunction, so that inline shows you how it runs the show.
|
| For example:
|
| require(RcppArmadillo)
| require(inline)
|
| f <- cxxfunction( , '
| arma::mat x(2,2) ;
| NumericMatrix res = wrap( x + x ) ;
| return res ;
| ', plugin = "RcppArmadillo", verbose = TRUE )
|
| When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
|
| For example, it shows me this on OSX:
|
| romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| Le chargement a n?cessit? le package : RcppArmadillo
| Le chargement a n?cessit? le package : Rcpp
| Le chargement a n?cessit? le package : methods
| Le chargement a n?cessit? le package : inline
| >> setting environment variables:
| PKG_LIBS =
| /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
|
| >> LinkingTo : RcppArmadillo, Rcpp
| CLINK_CPPFLAGS =
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
|
|
| >> Program source :
|
| 1 :
| 2 : // includes from the plugin
| 3 : #include <RcppArmadillo.h>
| 4 : #include <Rcpp.h>
| 5 :
| 6 :
| 7 : #ifndef BEGIN_RCPP
| 8 : #define BEGIN_RCPP
| 9 : #endif
| 10 :
| 11 : #ifndef END_RCPP
| 12 : #define END_RCPP
| 13 : #endif
| 14 :
| 15 : using namespace Rcpp;
| 16 :
| 17 :
| 18 : // user includes
| 19 :
| 20 :
| 21 : // declarations
| 22 : extern "C" {
| 23 : SEXP file313a14a1( ) ;
| 24 : }
| 25 :
| 26 : // definition
| 27 :
| 28 : SEXP file313a14a1( ){
| 29 : BEGIN_RCPP
| 30 :
| 31 : arma::mat x(2,2) ;
| 32 : NumericMatrix res = wrap( x + x ) ;
| 33 : return res ;
| 34 :
| 35 : END_RCPP
| 36 : }
| 37 :
| 38 :
| Compilation argument:
| /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| -I/Library/Frameworks/R.framework/Resources/include/x86_64
| -I/usr/local/include
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| dynamic_lookup -single_module -multiply_defined suppress
| -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| -Wl,-framework -Wl,CoreFoundation
|
| Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| PKG_CPPFLAGS if you prefer).
|
|
|
| Another tip with inline is that you can read the code from a file, e.g :
|
| f <- cxxfunction( ,
| paste( readLines("bla.cpp"), collapse = "\n") ,
| plugin = "RcppArmadillo", verbose = TRUE )
|
| This way you can import multiple files, etc ... while keeping the C++
| code out of the R code. I would still however very strongly recommend
| you to make a package. It is well documented, easy and it will save you
| some time.
|
| Romain
|
| --
| Romain Francois
| Professional R Enthusiast
| +33(0) 6 28 91 30 30
| http://romainfrancois.blog.free.fr
| |- http://bit.ly/fT2rZM : highlight 0.2-5
| |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| `- http://bit.ly/hovakS : RcppGSL initial release
|
|
|
| __________________________________________________________________________
|
| This email message is for the sole use of the intended recipient(s) and
| may contain confidential information. Any unauthorized review, use,
| disclosure or distribution is prohibited. If you are not the intended
| recipient, please contact the sender by reply email and destroy all copies
| of the original message.
|
| _______________________________________________
| 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
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
On 14 December 2010 at 08:31, Savitsky, Terrance wrote:
| This header is not in the helpful examples, nor in the simple 'bla.cpp' Romain crafted that employed RcppArmadillo. Is the requirement for me to add this header related to the Windows version of Rcpp or is it universal and obvious to a C++ developer? a) Well it just works over here: R> src <- 'char buffer[128]; + snprintf(buffer, 127, "Hello, %s\\n", "world"); + return(Rcpp::wrap(std::string(buffer)));' R> foo <- cxxfunction(, src, plugin="Rcpp") R> foo() [1] "Hello, world\n" R> b) My version of Rtools (ie g++ on Windows) has cstdio (as the C++ version of stdio.h) and defines snprintf. Hope this helps, Dirk | Thanks. Terrance | | -----Original Message----- | From: Dirk Eddelbuettel [mailto:edd at debian.org] | Sent: Tuesday, December 14, 2010 7:56 AM | To: Savitsky, Terrance | Cc: rcpp-devel at r-forge.wu-wien.ac.at | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP | |
| On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| | Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
|
| snprintf is defined in the cstdio header.
|
| Dirk
|
| |
| | Thanks, Terrance Savitsky
| |
| | -----Original Message-----
| | From: Romain Francois [mailto:romain at r-enthusiasts.com]
| | Sent: Sunday, December 12, 2010 3:58 AM
| | To: Savitsky, Terrance
| | Cc: rcpp-devel at r-forge.wu-wien.ac.at
| | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
| |
| | Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| | > Hello,
| | >
| | > I employ a variant of the following lines in a cygwin bash session in
| | > Windows XP to compile my .cpp file.
| | >
| | > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| | >
| | > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| | >
| | > $ R CMD SHLIB fastLm.cpp
| | >
| | > I receive the following compile error:
| | >
| | > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| | > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| | > fastLm.o
| | >
| | > G++:Rscript.exe: No such file or directory
| | >
| | > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| | >
| | > fastLm.cpp:2: error: 'SEXP' does not have name a type
| | >
| | > I've included the R bin directory containing Rscript.exe to the PATH
| | > environment statement. Should one use a different syntax for windows to
| | > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| | > inline, though my code is 600 lines and I will have multiple versions,
| | > so using the old approach may provide the most modular de-bugging
| | > approach vs. re-installing a package as I add files).
| | >
| | > Thanks, Terrance Savitsky
| |
| | Hello,
| |
| | I would strongly advise you to make it a package, especially if you deal
| | with multiple files, etc ...
| |
| | One thing you might want to consider is to use the verbose argument of
| | cxxfunction, so that inline shows you how it runs the show.
| |
| | For example:
| |
| | require(RcppArmadillo)
| | require(inline)
| |
| | f <- cxxfunction( , '
| | arma::mat x(2,2) ;
| | NumericMatrix res = wrap( x + x ) ;
| | return res ;
| | ', plugin = "RcppArmadillo", verbose = TRUE )
| |
| | When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
| |
| | For example, it shows me this on OSX:
| |
| | romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| | Le chargement a n?cessit? le package : RcppArmadillo
| | Le chargement a n?cessit? le package : Rcpp
| | Le chargement a n?cessit? le package : methods
| | Le chargement a n?cessit? le package : inline
| | >> setting environment variables:
| | PKG_LIBS =
| | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
| |
| | >> LinkingTo : RcppArmadillo, Rcpp
| | CLINK_CPPFLAGS =
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| |
| |
| | >> Program source :
| |
| | 1 :
| | 2 : // includes from the plugin
| | 3 : #include <RcppArmadillo.h>
| | 4 : #include <Rcpp.h>
| | 5 :
| | 6 :
| | 7 : #ifndef BEGIN_RCPP
| | 8 : #define BEGIN_RCPP
| | 9 : #endif
| | 10 :
| | 11 : #ifndef END_RCPP
| | 12 : #define END_RCPP
| | 13 : #endif
| | 14 :
| | 15 : using namespace Rcpp;
| | 16 :
| | 17 :
| | 18 : // user includes
| | 19 :
| | 20 :
| | 21 : // declarations
| | 22 : extern "C" {
| | 23 : SEXP file313a14a1( ) ;
| | 24 : }
| | 25 :
| | 26 : // definition
| | 27 :
| | 28 : SEXP file313a14a1( ){
| | 29 : BEGIN_RCPP
| | 30 :
| | 31 : arma::mat x(2,2) ;
| | 32 : NumericMatrix res = wrap( x + x ) ;
| | 33 : return res ;
| | 34 :
| | 35 : END_RCPP
| | 36 : }
| | 37 :
| | 38 :
| | Compilation argument:
| | /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| | file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| | g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| | -I/Library/Frameworks/R.framework/Resources/include/x86_64
| | -I/usr/local/include
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| | -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| | g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| | dynamic_lookup -single_module -multiply_defined suppress
| | -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| | -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| | -Wl,-framework -Wl,CoreFoundation
| |
| | Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| | PKG_CPPFLAGS if you prefer).
| |
| |
| |
| | Another tip with inline is that you can read the code from a file, e.g :
| |
| | f <- cxxfunction( ,
| | paste( readLines("bla.cpp"), collapse = "\n") ,
| | plugin = "RcppArmadillo", verbose = TRUE )
| |
| | This way you can import multiple files, etc ... while keeping the C++
| | code out of the R code. I would still however very strongly recommend
| | you to make a package. It is well documented, easy and it will save you
| | some time.
| |
| | Romain
| |
| | --
| | Romain Francois
| | Professional R Enthusiast
| | +33(0) 6 28 91 30 30
| | http://romainfrancois.blog.free.fr
| | |- http://bit.ly/fT2rZM : highlight 0.2-5
| | |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| | `- http://bit.ly/hovakS : RcppGSL initial release
| |
| |
| |
| | __________________________________________________________________________
| |
| | This email message is for the sole use of the intended recipient(s) and
| | may contain confidential information. Any unauthorized review, use,
| | disclosure or distribution is prohibited. If you are not the intended
| | recipient, please contact the sender by reply email and destroy all copies
| | of the original message.
| |
| | _______________________________________________
| | 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
|
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Thanks. Does it work with this code employing RcppArmadillo?
#include <RcppArmadillo.h>
using namespace Rcpp;
extern "C" SEXP foo(){
arma::mat x(2,2);
NumericMatrix res = wrap (x + x);
return res;
}
Are you able to compile and link via R CMD SHLIB with this code snippet? That something works via inline, but not R CMD SHLIB, leaves me concerned I will be unable to employ code composed under RcppArmadillo to build a package. I have been able to successively compile and build RcppArmadillo code in my Windows XP installation through inline. What I'm not able to do is the same through R CMD SHLIB. With Romain's help, the Rcpp/RcppArmadillo dependencies are resolved, but not the simple snprintf error. I don't think there's an issue with my installation of the Rtools toolchain as I've reviewed it a number of times (including environment variable settings). Including additional headers or namespace declarations is not solving this problem. I'm wondering if there is not a Windows issue driving it and whether the root cause is something other than making additional includes on my end.
Thanks.
-----Original Message-----
From: Dirk Eddelbuettel [mailto:edd at debian.org]
Sent: Tuesday, December 14, 2010 8:52 AM
To: Savitsky, Terrance
Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at
Subject: RE: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP
On 14 December 2010 at 08:31, Savitsky, Terrance wrote:
| This header is not in the helpful examples, nor in the simple 'bla.cpp' Romain crafted that employed RcppArmadillo. Is the requirement for me to add this header related to the Windows version of Rcpp or is it universal and obvious to a C++ developer? a) Well it just works over here: R> src <- 'char buffer[128]; + snprintf(buffer, 127, "Hello, %s\\n", "world"); + return(Rcpp::wrap(std::string(buffer)));' R> foo <- cxxfunction(, src, plugin="Rcpp") R> foo() [1] "Hello, world\n" R> b) My version of Rtools (ie g++ on Windows) has cstdio (as the C++ version of stdio.h) and defines snprintf. Hope this helps, Dirk | Thanks. Terrance | | -----Original Message----- | From: Dirk Eddelbuettel [mailto:edd at debian.org] | Sent: Tuesday, December 14, 2010 7:56 AM | To: Savitsky, Terrance | Cc: rcpp-devel at r-forge.wu-wien.ac.at | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP | |
| On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| | Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
|
| snprintf is defined in the cstdio header.
|
| Dirk
|
| |
| | Thanks, Terrance Savitsky
| |
| | -----Original Message-----
| | From: Romain Francois [mailto:romain at r-enthusiasts.com]
| | Sent: Sunday, December 12, 2010 3:58 AM
| | To: Savitsky, Terrance
| | Cc: rcpp-devel at r-forge.wu-wien.ac.at
| | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
| |
| | Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| | > Hello,
| | >
| | > I employ a variant of the following lines in a cygwin bash session in
| | > Windows XP to compile my .cpp file.
| | >
| | > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| | >
| | > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| | >
| | > $ R CMD SHLIB fastLm.cpp
| | >
| | > I receive the following compile error:
| | >
| | > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| | > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| | > fastLm.o
| | >
| | > G++:Rscript.exe: No such file or directory
| | >
| | > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| | >
| | > fastLm.cpp:2: error: 'SEXP' does not have name a type
| | >
| | > I've included the R bin directory containing Rscript.exe to the PATH
| | > environment statement. Should one use a different syntax for windows to
| | > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| | > inline, though my code is 600 lines and I will have multiple versions,
| | > so using the old approach may provide the most modular de-bugging
| | > approach vs. re-installing a package as I add files).
| | >
| | > Thanks, Terrance Savitsky
| |
| | Hello,
| |
| | I would strongly advise you to make it a package, especially if you deal
| | with multiple files, etc ...
| |
| | One thing you might want to consider is to use the verbose argument of
| | cxxfunction, so that inline shows you how it runs the show.
| |
| | For example:
| |
| | require(RcppArmadillo)
| | require(inline)
| |
| | f <- cxxfunction( , '
| | arma::mat x(2,2) ;
| | NumericMatrix res = wrap( x + x ) ;
| | return res ;
| | ', plugin = "RcppArmadillo", verbose = TRUE )
| |
| | When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
| |
| | For example, it shows me this on OSX:
| |
| | romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| | Le chargement a n?cessit? le package : RcppArmadillo
| | Le chargement a n?cessit? le package : Rcpp
| | Le chargement a n?cessit? le package : methods
| | Le chargement a n?cessit? le package : inline
| | >> setting environment variables:
| | PKG_LIBS =
| | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
| |
| | >> LinkingTo : RcppArmadillo, Rcpp
| | CLINK_CPPFLAGS =
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| |
| |
| | >> Program source :
| |
| | 1 :
| | 2 : // includes from the plugin
| | 3 : #include <RcppArmadillo.h>
| | 4 : #include <Rcpp.h>
| | 5 :
| | 6 :
| | 7 : #ifndef BEGIN_RCPP
| | 8 : #define BEGIN_RCPP
| | 9 : #endif
| | 10 :
| | 11 : #ifndef END_RCPP
| | 12 : #define END_RCPP
| | 13 : #endif
| | 14 :
| | 15 : using namespace Rcpp;
| | 16 :
| | 17 :
| | 18 : // user includes
| | 19 :
| | 20 :
| | 21 : // declarations
| | 22 : extern "C" {
| | 23 : SEXP file313a14a1( ) ;
| | 24 : }
| | 25 :
| | 26 : // definition
| | 27 :
| | 28 : SEXP file313a14a1( ){
| | 29 : BEGIN_RCPP
| | 30 :
| | 31 : arma::mat x(2,2) ;
| | 32 : NumericMatrix res = wrap( x + x ) ;
| | 33 : return res ;
| | 34 :
| | 35 : END_RCPP
| | 36 : }
| | 37 :
| | 38 :
| | Compilation argument:
| | /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| | file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| | g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| | -I/Library/Frameworks/R.framework/Resources/include/x86_64
| | -I/usr/local/include
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| | -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| | g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| | dynamic_lookup -single_module -multiply_defined suppress
| | -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| | -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| | -Wl,-framework -Wl,CoreFoundation
| |
| | Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| | PKG_CPPFLAGS if you prefer).
| |
| |
| |
| | Another tip with inline is that you can read the code from a file, e.g :
| |
| | f <- cxxfunction( ,
| | paste( readLines("bla.cpp"), collapse = "\n") ,
| | plugin = "RcppArmadillo", verbose = TRUE )
| |
| | This way you can import multiple files, etc ... while keeping the C++
| | code out of the R code. I would still however very strongly recommend
| | you to make a package. It is well documented, easy and it will save you
| | some time.
| |
| | Romain
| |
| | --
| | Romain Francois
| | Professional R Enthusiast
| | +33(0) 6 28 91 30 30
| | http://romainfrancois.blog.free.fr
| | |- http://bit.ly/fT2rZM : highlight 0.2-5
| | |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| | `- http://bit.ly/hovakS : RcppGSL initial release
| |
| |
| |
| | __________________________________________________________________________
| |
| | This email message is for the sole use of the intended recipient(s) and
| | may contain confidential information. Any unauthorized review, use,
| | disclosure or distribution is prohibited. If you are not the intended
| | recipient, please contact the sender by reply email and destroy all copies
| | of the original message.
| |
| | _______________________________________________
| | 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
|
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
On 14 December 2010 at 10:12, Savitsky, Terrance wrote:
| Thanks. Does it work with this code employing RcppArmadillo?
|
| #include <RcppArmadillo.h>
|
| using namespace Rcpp;
| extern "C" SEXP foo(){
| arma::mat x(2,2);
| NumericMatrix res = wrap (x + x);
| return res;
| }
|
| Are you able to compile and link via R CMD SHLIB with this code snippet?
| That something works via inline, but not R CMD SHLIB,
Maybe you are not using the settings that inline uses.
It works here:
R> src <- 'arma::mat x(2,2);
+ NumericMatrix res = wrap (x + x);
+ return res;'
R> bar <- cxxfunction(, src, plugin="RcppArmadillo")
R> bar()
[,1] [,2]
[1,] 0 0
[2,] 0 0
R>
| leaves me concerned I will be unable to employ code composed under
| RcppArmadillo to build a package. I have been able to successively compile
| and build RcppArmadillo code in my Windows XP installation through inline.
Good. Now learn about
a) the verbose=TRUE argument to cxxfunction()
b) the RcppArmadillo.package.skeleton() function
| What I'm not able to do is the same through R CMD SHLIB. With Romain's help, the Rcpp/RcppArmadillo dependencies are resolved, but not the simple snprintf error. I don't think there's an issue with my installation of the Rtools toolchain as I've reviewed it a number of times (including environment variable settings). Including additional headers or namespace declarations is not solving this problem. I'm wondering if there is not a Windows issue driving it and whether the root cause is something other than making additional includes on my end.
snprintf is really, really standard.
Dirk
| Thanks.
|
|
| -----Original Message-----
| From: Dirk Eddelbuettel [mailto:edd at debian.org]
| Sent: Tuesday, December 14, 2010 8:52 AM
| To: Savitsky, Terrance
| Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at
| Subject: RE: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP
|
|
| On 14 December 2010 at 08:31, Savitsky, Terrance wrote:
| | This header is not in the helpful examples, nor in the simple 'bla.cpp' Romain crafted that employed RcppArmadillo. Is the requirement for me to add this header related to the Windows version of Rcpp or is it universal and obvious to a C++ developer? | | a) Well it just works over here: | | R> src <- 'char buffer[128]; | + snprintf(buffer, 127, "Hello, %s\\n", "world"); | + return(Rcpp::wrap(std::string(buffer)));' | R> foo <- cxxfunction(, src, plugin="Rcpp") | R> foo() | [1] "Hello, world\n" | R> | | | b) My version of Rtools (ie g++ on Windows) has cstdio (as the C++ version of | stdio.h) and defines snprintf. | | | Hope this helps, Dirk | | | | | Thanks. Terrance | | | | -----Original Message----- | | From: Dirk Eddelbuettel [mailto:edd at debian.org] | | Sent: Tuesday, December 14, 2010 7:56 AM | | To: Savitsky, Terrance | | Cc: rcpp-devel at r-forge.wu-wien.ac.at | | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP | | | |
| | On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| | | Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
| |
| | snprintf is defined in the cstdio header.
| |
| | Dirk
| |
| | |
| | | Thanks, Terrance Savitsky
| | |
| | | -----Original Message-----
| | | From: Romain Francois [mailto:romain at r-enthusiasts.com]
| | | Sent: Sunday, December 12, 2010 3:58 AM
| | | To: Savitsky, Terrance
| | | Cc: rcpp-devel at r-forge.wu-wien.ac.at
| | | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
| | |
| | | Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| | | > Hello,
| | | >
| | | > I employ a variant of the following lines in a cygwin bash session in
| | | > Windows XP to compile my .cpp file.
| | | >
| | | > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| | | >
| | | > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| | | >
| | | > $ R CMD SHLIB fastLm.cpp
| | | >
| | | > I receive the following compile error:
| | | >
| | | > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| | | > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| | | > fastLm.o
| | | >
| | | > G++:Rscript.exe: No such file or directory
| | | >
| | | > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| | | >
| | | > fastLm.cpp:2: error: 'SEXP' does not have name a type
| | | >
| | | > I've included the R bin directory containing Rscript.exe to the PATH
| | | > environment statement. Should one use a different syntax for windows to
| | | > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| | | > inline, though my code is 600 lines and I will have multiple versions,
| | | > so using the old approach may provide the most modular de-bugging
| | | > approach vs. re-installing a package as I add files).
| | | >
| | | > Thanks, Terrance Savitsky
| | |
| | | Hello,
| | |
| | | I would strongly advise you to make it a package, especially if you deal
| | | with multiple files, etc ...
| | |
| | | One thing you might want to consider is to use the verbose argument of
| | | cxxfunction, so that inline shows you how it runs the show.
| | |
| | | For example:
| | |
| | | require(RcppArmadillo)
| | | require(inline)
| | |
| | | f <- cxxfunction( , '
| | | arma::mat x(2,2) ;
| | | NumericMatrix res = wrap( x + x ) ;
| | | return res ;
| | | ', plugin = "RcppArmadillo", verbose = TRUE )
| | |
| | | When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
| | |
| | | For example, it shows me this on OSX:
| | |
| | | romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| | | Le chargement a n?cessit? le package : RcppArmadillo
| | | Le chargement a n?cessit? le package : Rcpp
| | | Le chargement a n?cessit? le package : methods
| | | Le chargement a n?cessit? le package : inline
| | | >> setting environment variables:
| | | PKG_LIBS =
| | | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | | $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
| | |
| | | >> LinkingTo : RcppArmadillo, Rcpp
| | | CLINK_CPPFLAGS =
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| | |
| | |
| | | >> Program source :
| | |
| | | 1 :
| | | 2 : // includes from the plugin
| | | 3 : #include <RcppArmadillo.h>
| | | 4 : #include <Rcpp.h>
| | | 5 :
| | | 6 :
| | | 7 : #ifndef BEGIN_RCPP
| | | 8 : #define BEGIN_RCPP
| | | 9 : #endif
| | | 10 :
| | | 11 : #ifndef END_RCPP
| | | 12 : #define END_RCPP
| | | 13 : #endif
| | | 14 :
| | | 15 : using namespace Rcpp;
| | | 16 :
| | | 17 :
| | | 18 : // user includes
| | | 19 :
| | | 20 :
| | | 21 : // declarations
| | | 22 : extern "C" {
| | | 23 : SEXP file313a14a1( ) ;
| | | 24 : }
| | | 25 :
| | | 26 : // definition
| | | 27 :
| | | 28 : SEXP file313a14a1( ){
| | | 29 : BEGIN_RCPP
| | | 30 :
| | | 31 : arma::mat x(2,2) ;
| | | 32 : NumericMatrix res = wrap( x + x ) ;
| | | 33 : return res ;
| | | 34 :
| | | 35 : END_RCPP
| | | 36 : }
| | | 37 :
| | | 38 :
| | | Compilation argument:
| | | /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| | | file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| | | g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| | | -I/Library/Frameworks/R.framework/Resources/include/x86_64
| | | -I/usr/local/include
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| | | -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| | | g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| | | dynamic_lookup -single_module -multiply_defined suppress
| | | -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| | | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| | | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| | | -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| | | -Wl,-framework -Wl,CoreFoundation
| | |
| | | Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| | | PKG_CPPFLAGS if you prefer).
| | |
| | |
| | |
| | | Another tip with inline is that you can read the code from a file, e.g :
| | |
| | | f <- cxxfunction( ,
| | | paste( readLines("bla.cpp"), collapse = "\n") ,
| | | plugin = "RcppArmadillo", verbose = TRUE )
| | |
| | | This way you can import multiple files, etc ... while keeping the C++
| | | code out of the R code. I would still however very strongly recommend
| | | you to make a package. It is well documented, easy and it will save you
| | | some time.
| | |
| | | Romain
| | |
| | | --
| | | Romain Francois
| | | Professional R Enthusiast
| | | +33(0) 6 28 91 30 30
| | | http://romainfrancois.blog.free.fr
| | | |- http://bit.ly/fT2rZM : highlight 0.2-5
| | | |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| | | `- http://bit.ly/hovakS : RcppGSL initial release
| | |
| | |
| | |
| | | __________________________________________________________________________
| | |
| | | This email message is for the sole use of the intended recipient(s) and
| | | may contain confidential information. Any unauthorized review, use,
| | | disclosure or distribution is prohibited. If you are not the intended
| | | recipient, please contact the sender by reply email and destroy all copies
| | | of the original message.
| | |
| | | _______________________________________________
| | | 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
| |
| | --
| | Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
|
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Sorry for not being clear. I'd already used verbose=T with inline to check the compile and build steps. The scripts are identical, but inline works and R CMD does not. I've used simpler and simpler examples and re-focused on Rcpp away from RcppArmadillo in an attempt to isolate the problem.
So what I did next was to build a package skeleton under Rcpp with that included the canonical C++ code and R script (Rcpp_hello_world) included there. I built it, but when I checked it; the compile step completed, but the build broke, with the following message:
* installing *source* package 'fooRcpp' ...
** libs
g++ -I"C:/PROGRA~1/R/R-212~1.0/include" -I"C:/PROGRA~1/R/R-212~1.0/library/Rcpp/include" -O2 -Wall -pedantic -c rcpp_hello_world.cpp -o rcpp_hello_world.o
g++ -shared -s -static-libgcc -o fooRcpp.dll tmp.def rcpp_hello_world.o C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a -LC:/PROGRA~1/R/R-212~1.0/bin/i386 -lR
C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a(RcppCommon.o):RcppCommon.cpp:(.text+0x78a): undefined reference to `__CRT_MT'
C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a(RObject.o):RObject.cpp:(.text+0x58a): undefined reference to `__CRT_MT'
C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a(RObject.o):RObject.cpp:(.text$_ZNSt6vectorISsSaISsEED1Ev[std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~vector()]+0x44): undefined reference to `__CRT_MT'
C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a(RObject.o):RObject.cpp:(.text$_ZNSt12_Destroy_auxILb0EE9__destroyIPSsEEvT_S3_[void std::_Destroy_aux<false>::__destroy<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)]+0x36): undefined reference to `__CRT_MT'
C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a(RObject.o):RObject.cpp:(.text$_ZNSt6vectorISsSaISsEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPSsS1_EERKSs[std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x1e6): undefined reference to `__CRT_MT'
C:/PROGRA~1/R/R-212~1.0/library/Rcpp/lib/i386/libRcpp.a(RObject.o):RObject.cpp:(.text$_ZNSt6vectorISsSaISsEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPSsS1_EERKSs[std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x245): more undefined references to `__CRT_MT' follow
collect2: ld returned 1 exit status
ERROR: compilation failed for package 'fooRcpp'
* removing 'C:/DOCUME~1/savitsky/MYDOCU~1/FOORCP~1.RCH/fooRcpp'
I also attempted to build a package under RcppArmadillo using the fastLm C++ code. This is the same code from which I attempted to create a SHLIB. Not surprisingly, I receive the same compile error as before when checking the package:
* installing *source* package 'foo' ...
** libs
g++ -I"C:/PROGRA~1/R/R-212~1.0/include" -I"C:/PROGRA~1/R/R-212~1.0/library/Rcpp/include" -I"C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include" -O2 -Wall -pedantic -c fastLmNoR.cpp -o fastLmNoR.o
In file included from C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo:111,
from C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/RcppArmadilloForward.h:36,
from C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/RcppArmadillo.h:25,
from fastLmNoR.cpp:1:
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp: In function 'std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::format, T2>&)':
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp:146: error: 'snprintf' is not a member of 'std'
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp: In function 'std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::format, T2>, T3>&)':
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp:198: error: 'snprintf' is not a member of 'std'
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp: In function 'std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::format, T2>, T3>, T4>&)':
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp:250: error: 'snprintf' is not a member of 'std'
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp: In function 'std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::format, T2>, T3>, T4>, T5>&)':
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp:302: error: 'snprintf' is not a member of 'std'
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp: In function 'std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::format, T2>, T3>, T4>, T5>, T6>&)':
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp:354: error: 'snprintf' is not a member of 'std'
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp: In function 'std::string arma::arma_boost::str(const arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::basic_format<arma::arma_boost::format, T2>, T3>, T4>, T5>, T6>, T7>&)':
C:/PROGRA~1/R/R-212~1.0/library/RcppArmadillo/include/armadillo_bits/format_wrap.hpp:406: error: 'snprintf' is not a member of 'std'
make: *** [fastLmNoR.o] Error 1
ERROR: compilation failed for package 'foo'
* removing 'C:/DOCUME~1/savitsky/MYDOCU~1/FOO~1.RCH/foo'
I'm unable to discover a pattern between these (and other) compile and build errors I'm achieving that would help me solve it. As mentioned, the scripts compile and build fine with inline under the same flag texts. The snprintf issue that appears when I employ RcppArmadillo is not fixable by including cstdio, cstring or locale. Anyway, it doesn't make sense that an idiosyncratic tweak under one scenario will fix the other errors I receive. Again, my Rtools installation is fine with nothing obvious there. I'd appreciate your helping me think through what factors would cause inline to work and R CMD to not when the includes, namespace, wrappers and flag text are *identical* between the two. Anyway, I'm at whit's end since I'm unable to build a package through Rcpp.
Thanks, Terrance.
-----Original Message-----
From: Dirk Eddelbuettel [mailto:edd at debian.org]
Sent: Tuesday, December 14, 2010 10:34 AM
To: Savitsky, Terrance
Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at
Subject: RE: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP
On 14 December 2010 at 10:12, Savitsky, Terrance wrote:
| Thanks. Does it work with this code employing RcppArmadillo?
|
| #include <RcppArmadillo.h>
|
| using namespace Rcpp;
| extern "C" SEXP foo(){
| arma::mat x(2,2);
| NumericMatrix res = wrap (x + x);
| return res;
| }
|
| Are you able to compile and link via R CMD SHLIB with this code snippet?
| That something works via inline, but not R CMD SHLIB,
Maybe you are not using the settings that inline uses.
It works here:
R> src <- 'arma::mat x(2,2);
+ NumericMatrix res = wrap (x + x);
+ return res;'
R> bar <- cxxfunction(, src, plugin="RcppArmadillo")
R> bar()
[,1] [,2]
[1,] 0 0
[2,] 0 0
R>
| leaves me concerned I will be unable to employ code composed under
| RcppArmadillo to build a package. I have been able to successively compile
| and build RcppArmadillo code in my Windows XP installation through inline.
Good. Now learn about
a) the verbose=TRUE argument to cxxfunction()
b) the RcppArmadillo.package.skeleton() function
| What I'm not able to do is the same through R CMD SHLIB. With Romain's help, the Rcpp/RcppArmadillo dependencies are resolved, but not the simple snprintf error. I don't think there's an issue with my installation of the Rtools toolchain as I've reviewed it a number of times (including environment variable settings). Including additional headers or namespace declarations is not solving this problem. I'm wondering if there is not a Windows issue driving it and whether the root cause is something other than making additional includes on my end.
snprintf is really, really standard.
Dirk
| Thanks.
|
|
| -----Original Message-----
| From: Dirk Eddelbuettel [mailto:edd at debian.org]
| Sent: Tuesday, December 14, 2010 8:52 AM
| To: Savitsky, Terrance
| Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at
| Subject: RE: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP
|
|
| On 14 December 2010 at 08:31, Savitsky, Terrance wrote:
| | This header is not in the helpful examples, nor in the simple 'bla.cpp' Romain crafted that employed RcppArmadillo. Is the requirement for me to add this header related to the Windows version of Rcpp or is it universal and obvious to a C++ developer? | | a) Well it just works over here: | | R> src <- 'char buffer[128]; | + snprintf(buffer, 127, "Hello, %s\\n", "world"); | + return(Rcpp::wrap(std::string(buffer)));' | R> foo <- cxxfunction(, src, plugin="Rcpp") | R> foo() | [1] "Hello, world\n" | R> | | | b) My version of Rtools (ie g++ on Windows) has cstdio (as the C++ version of | stdio.h) and defines snprintf. | | | Hope this helps, Dirk | | | | | Thanks. Terrance | | | | -----Original Message----- | | From: Dirk Eddelbuettel [mailto:edd at debian.org] | | Sent: Tuesday, December 14, 2010 7:56 AM | | To: Savitsky, Terrance | | Cc: rcpp-devel at r-forge.wu-wien.ac.at | | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB onWindows XP | | | |
| | On 13 December 2010 at 12:23, Savitsky, Terrance wrote:
| | | Hello Romain, Thank you for your expertise. I will use the documentation to make a package. At this point, however, I want to see every method I've tried work, however, so that I understand any and all differences I might expect for developing with Rcpp/RcppArmadillo under Windows XP. So I followed the process (using Verbose=TRUE under an inline invocation) with the bla.cpp you included for me to obtain PKG_LIBS and CLINK-CPPFLAGS values. When I return to my cygwin bash shell session and attempt to compile and link bla.cpp, it does now seem to properly source my #include<RcppArmadillo.h>. statement. I do, however, receive the following error: 'snprintf' is not a member of 'std'. So I guess I'm missing a header linked to std::snprintf. The only thing that comes to mind is that I have somehow corrupted my installation of Rcpp. I would appreciate any insight you would offer.
| |
| | snprintf is defined in the cstdio header.
| |
| | Dirk
| |
| | |
| | | Thanks, Terrance Savitsky
| | |
| | | -----Original Message-----
| | | From: Romain Francois [mailto:romain at r-enthusiasts.com]
| | | Sent: Sunday, December 12, 2010 3:58 AM
| | | To: Savitsky, Terrance
| | | Cc: rcpp-devel at r-forge.wu-wien.ac.at
| | | Subject: Re: [Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP
| | |
| | | Le 12/12/10 04:03, Savitsky, Terrance a ?crit :
| | | > Hello,
| | | >
| | | > I employ a variant of the following lines in a cygwin bash session in
| | | > Windows XP to compile my .cpp file.
| | | >
| | | > $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
| | | >
| | | > $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
| | | >
| | | > $ R CMD SHLIB fastLm.cpp
| | | >
| | | > I receive the following compile error:
| | | >
| | | > G++ -I"C:/PROGRA~1/R/R-212~1.0/include" Rscript.exe -e
| | | > "RcppArmadillo:::CxxxFlags()" -O2 - Wall -pedantic - c fastLm.cpp - o
| | | > fastLm.o
| | | >
| | | > G++:Rscript.exe: No such file or directory
| | | >
| | | > fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
| | | >
| | | > fastLm.cpp:2: error: 'SEXP' does not have name a type
| | | >
| | | > I've included the R bin directory containing Rscript.exe to the PATH
| | | > environment statement. Should one use a different syntax for windows to
| | | > capture RcppArmadillo dependencies? (Fyi, I am able to build using
| | | > inline, though my code is 600 lines and I will have multiple versions,
| | | > so using the old approach may provide the most modular de-bugging
| | | > approach vs. re-installing a package as I add files).
| | | >
| | | > Thanks, Terrance Savitsky
| | |
| | | Hello,
| | |
| | | I would strongly advise you to make it a package, especially if you deal
| | | with multiple files, etc ...
| | |
| | | One thing you might want to consider is to use the verbose argument of
| | | cxxfunction, so that inline shows you how it runs the show.
| | |
| | | For example:
| | |
| | | require(RcppArmadillo)
| | | require(inline)
| | |
| | | f <- cxxfunction( , '
| | | arma::mat x(2,2) ;
| | | NumericMatrix res = wrap( x + x ) ;
| | | return res ;
| | | ', plugin = "RcppArmadillo", verbose = TRUE )
| | |
| | | When you run this, you'll see what inline does with the PKG_LIBS, etc ...:
| | |
| | | For example, it shows me this on OSX:
| | |
| | | romain at naxos ~/svn/rcpp/pkg $ Rscript bla.R
| | | Le chargement a n?cessit? le package : RcppArmadillo
| | | Le chargement a n?cessit? le package : Rcpp
| | | Le chargement a n?cessit? le package : methods
| | | Le chargement a n?cessit? le package : inline
| | | >> setting environment variables:
| | | PKG_LIBS =
| | | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | | $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
| | |
| | | >> LinkingTo : RcppArmadillo, Rcpp
| | | CLINK_CPPFLAGS =
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| | |
| | |
| | | >> Program source :
| | |
| | | 1 :
| | | 2 : // includes from the plugin
| | | 3 : #include <RcppArmadillo.h>
| | | 4 : #include <Rcpp.h>
| | | 5 :
| | | 6 :
| | | 7 : #ifndef BEGIN_RCPP
| | | 8 : #define BEGIN_RCPP
| | | 9 : #endif
| | | 10 :
| | | 11 : #ifndef END_RCPP
| | | 12 : #define END_RCPP
| | | 13 : #endif
| | | 14 :
| | | 15 : using namespace Rcpp;
| | | 16 :
| | | 17 :
| | | 18 : // user includes
| | | 19 :
| | | 20 :
| | | 21 : // declarations
| | | 22 : extern "C" {
| | | 23 : SEXP file313a14a1( ) ;
| | | 24 : }
| | | 25 :
| | | 26 : // definition
| | | 27 :
| | | 28 : SEXP file313a14a1( ){
| | | 29 : BEGIN_RCPP
| | | 30 :
| | | 31 : arma::mat x(2,2) ;
| | | 32 : NumericMatrix res = wrap( x + x ) ;
| | | 33 : return res ;
| | | 34 :
| | | 35 : END_RCPP
| | | 36 : }
| | | 37 :
| | | 38 :
| | | Compilation argument:
| | | /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB
| | | file313a14a1.cpp 2> file313a14a1.cpp.err.txt
| | | g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
| | | -I/Library/Frameworks/R.framework/Resources/include/x86_64
| | | -I/usr/local/include
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include"
| | | -I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include"
| | | -fPIC -g -O3 -Wall -pipe -c file313a14a1.cpp -o file313a14a1.o
| | | g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
| | | dynamic_lookup -single_module -multiply_defined suppress
| | | -L/usr/local/lib -o file313a14a1.so file313a14a1.o
| | | /Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a
| | | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
| | | -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas
| | | -lgfortran -F/Library/Frameworks/R.framework/.. -framework R
| | | -Wl,-framework -Wl,CoreFoundation
| | |
| | | Then you can just hardcode PKG_LIBS and CLINK_CPPFLAGS (or use
| | | PKG_CPPFLAGS if you prefer).
| | |
| | |
| | |
| | | Another tip with inline is that you can read the code from a file, e.g :
| | |
| | | f <- cxxfunction( ,
| | | paste( readLines("bla.cpp"), collapse = "\n") ,
| | | plugin = "RcppArmadillo", verbose = TRUE )
| | |
| | | This way you can import multiple files, etc ... while keeping the C++
| | | code out of the R code. I would still however very strongly recommend
| | | you to make a package. It is well documented, easy and it will save you
| | | some time.
| | |
| | | Romain
| | |
| | | --
| | | Romain Francois
| | | Professional R Enthusiast
| | | +33(0) 6 28 91 30 30
| | | http://romainfrancois.blog.free.fr
| | | |- http://bit.ly/fT2rZM : highlight 0.2-5
| | | |- http://bit.ly/gpCSpH : Evolution of Rcpp code size
| | | `- http://bit.ly/hovakS : RcppGSL initial release
| | |
| | |
| | |
| | | __________________________________________________________________________
| | |
| | | This email message is for the sole use of the intended recipient(s) and
| | | may contain confidential information. Any unauthorized review, use,
| | | disclosure or distribution is prohibited. If you are not the intended
| | | recipient, please contact the sender by reply email and destroy all copies
| | | of the original message.
| | |
| | | _______________________________________________
| | | 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
| |
| | --
| | Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
|
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
On 14 December 2010 at 14:41, Savitsky, Terrance wrote:
| Sorry for not being clear. I'd already used verbose=T with inline to check the compile and build steps. The scripts are identical, but inline works and R CMD does not. I've used simpler and simpler examples and re-focused on Rcpp away from RcppArmadillo in an attempt to isolate the problem.
|
| So what I did next was to build a package skeleton under Rcpp with that included the canonical C++ code and R script (Rcpp_hello_world) included there. I built it, but when I checked it; the compile step completed, but the build broke, with the following message:
|
[...]
| I also attempted to build a package under RcppArmadillo using the fastLm C++ code. This is the same code from which I attempted to create a SHLIB. Not surprisingly, I receive the same compile error as before when checking the package:
[...]
| I'm unable to discover a pattern between these (and other) compile and build errors I'm achieving that would help me solve it. As mentioned, the scripts compile and build fine with inline under the same flag texts. The snprintf issue that appears when I employ RcppArmadillo is not fixable by including cstdio, cstring or locale. Anyway, it doesn't make sense that an idiosyncratic tweak under one scenario will fix the other errors I receive. Again, my Rtools installation is fine with nothing obvious there. I'd appreciate your helping me think through what factors would cause inline to work and R CMD to not when the includes, namespace, wrappers and flag text are *identical* between the two. Anyway, I'm at whit's end since I'm unable to build a package through Rcpp.
I am sorry but I do not have any further suggestions:
- the tools to use are documented in Writing R Extension etc
- it works for CRAN which creates Windows binaries of these packages from
source; dito for R-Forge
- I just rebuilt a package using Rcpp at work using the current Rtools and
it also 'just works'.
Sorry, Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Turns out the problem was my use of the cygwin bash shell with R CMD. When I switched to the DOS shell, everything worked (including package building under Rcpp and RcppArmadillo). So I send this note for documentation. -----Original Message----- From: Dirk Eddelbuettel [mailto:edd at debian.org] Sent: Tuesday, December 14, 2010 3:12 PM To: Savitsky, Terrance Cc: Dirk Eddelbuettel; rcpp-devel at r-forge.wu-wien.ac.at Subject: RE: [Rcpp-devel] Unable to build Package under Rcpp with Windows XP using canonical Example
On 14 December 2010 at 14:41, Savitsky, Terrance wrote:
| Sorry for not being clear. I'd already used verbose=T with inline to
check the compile and build steps. The scripts are identical, but
inline works and R CMD does not. I've used simpler and simpler examples
and re-focused on Rcpp away from RcppArmadillo in an attempt to isolate
the problem.
|
| So what I did next was to build a package skeleton under Rcpp with
that included the canonical C++ code and R script (Rcpp_hello_world)
included there. I built it, but when I checked it; the compile step
completed, but the build broke, with the following message:
|
[...]
| I also attempted to build a package under RcppArmadillo using the
fastLm C++ code. This is the same code from which I attempted to create
a SHLIB. Not surprisingly, I receive the same compile error as before
when checking the package:
[...]
| I'm unable to discover a pattern between these (and other) compile and
build errors I'm achieving that would help me solve it. As mentioned,
the scripts compile and build fine with inline under the same flag
texts. The snprintf issue that appears when I employ RcppArmadillo is
not fixable by including cstdio, cstring or locale. Anyway, it doesn't
make sense that an idiosyncratic tweak under one scenario will fix the
other errors I receive. Again, my Rtools installation is fine with
nothing obvious there. I'd appreciate your helping me think through
what factors would cause inline to work and R CMD to not when the
includes, namespace, wrappers and flag text are *identical* between the
two. Anyway, I'm at whit's end since I'm unable to build a package
through Rcpp.
I am sorry but I do not have any further suggestions:
- the tools to use are documented in Writing R Extension etc
- it works for CRAN which creates Windows binaries of these packages
from
source; dito for R-Forge
- I just rebuilt a package using Rcpp at work using the current Rtools
and
it also 'just works'.
Sorry, Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com __________________________________________________________________________ This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.