Re: [R] dyn.load() error: bad external relocation length

From: Duncan Temple Lang <duncan_at_wald.ucdavis.edu>
Date: Sat 29 Oct 2005 - 23:49:14 EST

Hi Walton.

.C/.Call are interfaces to _compiled_ C routines in a dynamically loaded library (DLL or DSO - shared object). A progra A program is often created from compiling C code into an executable. We can call the executable via system, but we cannot access its routines via .C/.Call.

So, if you have C code, use R CMD SHLIB to compile it into a loadable libray and use dyn.load() to load it. Putting the code in the src/ directory of a package makes the need to do this less explicit.

But if you want to use system(), again it can be done "portably" in a package.
Arrange that the package creates and puts the executable in the package's installed area. Arrange that the program is put in, say, inst/bin within the package and then it will be installed into the bin/ directory of the package. Then you can access it with

    system.file("bin", "myProg", package = "myPackageName")

and you can use that in your call to system().

The down side is that you will have to ensure that the program is built in a portable way. So if you won the C code, it is almost the same thing as building a DLL and using .C/.Call.

HTH    D.

Walton A. Green wrote:
> R-helpers,
>
> Is there an easy way to call an external (C) program using .C or .Call
> without including the code in a package. I know how to do it using
> system(), but that doesn't seem to be a permanent or portable solution.
> Initially I tried:
>
> .Call('filepath.to.c.function', arg1)
>
> and got this error:
>
> Error in .Call("filepath.to.c.function", "arg1", :
> "C" function name not in load table
>
> So read the section on foreign language interfaces in the Writing R
> Extensions manual but when I tried:
>
> dyn.load('filepath.to.c.function')
>
> I got:
>
> Error in dyn.load(x, as.logical(local), as.logical(now)) :
> unable to load shared library 'filepath.to.c.function':
> dlopen(filepath.to.c.function, 6): bad external relocation length
>
> Do you need to run R_registerRoutines before dyn.load()? I couldn't find
> any mention of this error on the web....
>
> Walton
>
> platform powerpc-apple-darwin7.9.0
> arch powerpc
> os darwin7.9.0
> system powerpc, darwin7.9.0
> status
> major 2
> minor 1.1
> year 2005
> month 06
> day 20
> language R
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Oct 29 23:55:15 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:53 EST