Problem with loading compiled c code in R x64 using dyn.load

I recently went from a 32bit laptop to a 64bit desktop (both win7). I just found out that I get an error now when loading dll's using dyn.load . I guess this is a simple mistake and I am overlooking something.

For example, I write this simple c function (foo.c):

void foo( int *x) {*x = *x + 1;}

Then compile it in command prompt:

R CMD SHLIB foo.c

Then in 32bit RI can use it in R:

> dyn.load("foo.dll")
> .C("foo",as.integer(1))
[[1]]
[1] 2

but in 64bit RI get:

> dyn.load("foo.dll")
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/Sacha/Documents/R/foo.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.
nd.

Edit:

For reference, R CMD can be forced in an architecture by using --arch 64x :

R --arch x64 CMD SHLIB foo.c

Quite clear actually, I knew I was making a rooky mistake:)


My guess is that you are compiling it to a 32 bit target. You need to build it on your 64 bit machine with 64 bit tools. You can't load a 32 bit DLL into a 64 bit process, and vice versa.


我所做的是每次编译一次--arch x64和--arch 32,并手动将相应的.dll(具有相同的名称)分别放在单独的文件夹src-x64和src-i386下,这两个文件夹在相同的目录src所在的目录。

链接地址: http://www.djcxy.com/p/4562.html

上一篇: CouchDB / NoSQL和域驱动设计?

下一篇: 使用dyn.load在R x64中加载已编译c代码的问题