An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20140721/3a958506/attachment.pl>
create R package include Fortran source code.
4 messages · yiqun yang, Duncan Murdoch, Charles C. Berry
On 21/07/2014 12:10 PM, yiqun yang wrote:
Hello, all
I am building a R package using Fortran source code. The Fortran code is a
subroutine. I can use "R CMD SHLIB bar.f -o bar.o" to create the shared
library. For the R package, I put the fortran file in the src/ and I use R
code as follows:
".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,libname)}
barfun<-function(n,x){
.Fortran("bar",as.integer(n),as.double(x))
}
package.skeleton(name="barpkg",list=c("barfun"))
--------------------------------------------------------------------------
I can build with "R CMD build barpkg", when I check the package with "R CMD
check barpkg", there is an error,
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object
'c:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/i386/bar.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
You will see more information in the files in the barpkg.Rcheck directory created during the check. You can see some of those messages on the screen if you do an explicit INSTALL. I'd guess that the compile failed, but can't guess why. Duncan Murdoch
Error: loading failed Execution halted *** arch - x64 ERROR: loading failed for 'i386' I don't know how to fix this error. Can anyone help me with this? Thanks. -Emily [[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20140721/0ca050bb/attachment.pl>
yiqun yang <emiliawxr <at> gmail.com> writes:
Thank you for your reply. First I try "R CMD INSTALL barpkg", then it gives similiar things:
------------------------------------------------------------- [deleted] -------------------------------------------------------------
2) I don't know how to check the "compile" problem. I just try to
"dyn.load" the shared object in /src-i386 and /src-x64 in the package, and
they both work well.
I am guessing there is some error in the R language.
".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,
libname)}
barfun<-function(n,x){
.Fortran("bar",as.integer(n),as.double(x))
}
package.skeleton(name="barpkg",list=c("barfun"))
I am not sure about this part. Can anyone give me some suggestion?
?.First.lib
refers to the base-defunct {base} help page which says:
[...]
# Defunct in 2.14.0
.First.lib(lib, pkg)
[...]
Details
Some of these have stubs which report that they are defunct, but most have
been removed completely (apart from being documented here).
[...]
====
So, don't use .First.lib.
Try a useDynLib directive in your NAMESPACE file.
You probably need to spend some time pondering
Writing R Extensions
especially section
1.5.4 useDynLib
HTH,
Chuck