Skip to content

.C() and C++ name mangling

3 messages · Andy Jacobson, Peter Dimitrov, Douglas Bates

#
Howdy,

        I'm working with some external code written in C++, which I
        would like to call via dyn.load() and .C() from R.  The
        function prototype looks like:

        gaRemin(int *, float *, float *, int *, float *, float *, 
                float *, float *, float *)

        but to call this function from R using .C() I have had to use
        the mangled version of this function name,

        gaRemin__FPiPfT1T0T1N41

        Is using the mangled name my best option, or is there some way
        that R knows to interpret unmangled function names from C++
        shared library objects?

        I'm concerned about portability of the resultant code in the
        case that name-mangling is handled differently from platform
        to platform.

        This is Linux, Redhat 7.2 with g++-2.96.

        Thanks for any help you can offer,

                Andy
#
Enclose the interface function, in your case gaRemin with extern "C"
statement like this:

extern "C"
{

	gaRemin(int *, float *, float *, int *, float *, float *, 
		float *, float *, float *) {
		...
	}

}

Also, look at the "Writing R Extensions" manual in R help, specifically
the chapter "System and foreign language interfaces", section
"Interfacing C++ code", for more information.

peter
On Wed, 2002-10-02 at 10:06, Andy Jacobson wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Andy Jacobson <andyj at splash.princeton.edu> writes:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._