问题描述
最近,我从一个32位的笔记本电脑去了一个64位台式机(包括WIN7)。我刚刚发现我现在得到一个错误加载DLL的使用 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.
例如,我写这个简单的C函数(foo.c的):
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
然后在32位R I在R中可以使用它:
Then in 32bit R I can use it in R:
> dyn.load("foo.dll")
> .C("foo",as.integer(1))
[[1]]
[1] 2
但在64位R I得到:
but in 64bit R I 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.
编辑:
有关参考,R CMD可以在一个架构通过使用强制 - 拱64倍
:
For reference, R CMD can be forced in an architecture by using --arch 64x
:
R --arch x64 CMD SHLIB foo.c
很清楚其实,我知道我是在rooky错误:)
Quite clear actually, I knew I was making a rooky mistake:)
推荐答案
我的猜测是,您需要将其编译成一个32位的目标。您需要64位工具来构建它的64位计算机上。你无法加载32位DLL到64位进程,反之亦然。
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.
这篇关于问题中的R 64装载编译C code。使用dyn.load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!