[R] Error when calling a dll procedure

Duncan Temple Lang duncan at research.bell-labs.com
Sun Nov 16 20:23:52 CET 2003


Hi Bernd.

  When you compile the code with a C++ compiler, it "mangles" the name
getPrimes into something that has type information (to allow other
routines with the same name but different signatures).  You need to
tell the compiler not to do this. And you use extern "C" to declare
it as a regular C symbol that should not be mangled.

  extern "C" {

   SEXP getPrimes(SEXP);
  }


Then recompile and all should be well.

 D.


Bernd Holleczek wrote:
> Dear experts,
> 
> I am a beginner in R and try to build dlls (Win XP, MinGW, R 1.7.1).
> So far, I have managed to create and to use some dlls with C code which
> worked properly.
> 
> Now I am stuck with a dll containing C++ code.
> 
> I have included some part of the source code (of an implementation of a
> function to find all primes below a given numeric value -> its just an exercises
> to get familar with R/C++).
> 
> >#include <vector>
> >
> >using namespace std;
> >
> >extern "C" {
> >#include <R.h>
> >#include <Rdefines.h>
> >}
> >
> >SEXP getPrimes(SEXP a)
> >{ 
> >SEXP c;
> >
>  
> //my implementation
> 
> >
> >return c;
> >}
> 
> Here is the output (hopefully without any typos) of the process building the
> dll:
> 
> >Rcmd SHLIB Primes.cc
> >making Primes.d from Primes.c
> >g++ -IE:\programs\R\rw1071\src\include -Wall -02 -c Primes.cc  -o Primes.o
> >ar cr Primes.a *.o
> >ranlib Primes.a
> >g++ --shared -s -o Primes.dll Primes.def Primes.a
> -LE:\programs\R\rw1071\src\gnuwin32 -lg2c -lR
> 
> 
> My PROBLEM is now that I can load the dll (no error message), but not access
> the function "getPrimes". Here is some output of the R console:
> 
> >> dyn.load("E:\\R_work5\\Primes")
> >> .Call("getPrimes", 100)
> >Error in .Call("getPrimes", 100) : .Call function name not in load table
> 
> 
> Has anybody been confronted with the same kind of difficulties?
> I'll appreciate suggestions on how to fix the problem.
> Thanks.
> 
> Regards,
> 
> Bernd Holleczek
> 
> 
> 
> -- 
> Bernd Holleczek <bernd.holleczek at gmx.de>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

-- 
_______________________________________________________________

Duncan Temple Lang                duncan at research.bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-3217
700 Mountain Avenue, Room 2C-259  fax:    (908)582-3340
Murray Hill, NJ  07974-2070       
         http://cm.bell-labs.com/stat/duncan




More information about the R-help mailing list