[Rd] programming with C++Builder 5
Simon Urbanek
simon.urbanek at math.uni-augsburg.de
Wed Dec 31 14:34:52 MET 2003
On Dec 31, 2003, at 10:17 AM, Edward Feng wrote:
> I am using C++ Builder 5 to develop windows GUI interface for a R
> library package. I have to pass R objects to and from C functions and
> also evaluate them within C functions. But I always got linking error
> message of "unresolved external functions" with those internal
> functions or macros defined in Rinternals.h file. I can not find the
> reason.
There are many possible reasons - you didn't say anything about how
you exactly access the DLL, create the R.lib etc. All I can do is to
imagine what you did wrong, so I hope this will cover some of it.
There are following pitfalls I can think of (I omitted obvious ones
like include paths and run-time issues like determining R_HOME etc.)
1) You should globally define Win32 in your project - depending on the
BCC you use this may not be the default, and R relies on it
2) C vs C++:
I assume that you'll be using C++ (otherwise there's no need for C++
Builder ;)). R.dll exports are all in C language, most of them are also
in the C calling convention. You must be aware of this when interfacing
externals. Note that there are several includes that you need to wrap
in export "C" { ... }!
If you see symbol "R_xxx" not defined then you have this C vs. C++
problem. If something else is wrong you should see symbol "_R_xxx" not
defined - that's in fact an improvement!
3) R.DEF
BCC and gcc disagree about the notations in the DEF file. I assume that
you won't use any STDCALL functions of R (it's just some bz2 func
etc.), so I'll skip that issue.
BCC is looking for the exports of the form _function - so you need to
modify the R.DEF supplied with R in order to be usable with BCC. You
need to do two things:
- remove all hints (the @nnn at the end of all lines)
- mangle all function names, i.e. the line:
R_DefParams @215
should become:
_R_DefParams=R_DefParams
This can be easily done by a simple script.
4) generate a R.lib with implib -c R R.def
Now you're ready to use R.dll in your program. But before you plunge
into writing some Win apps that interface to R, you should definitely
look at other projects that use R.dll - there is a lot of issues you
should be aware of, especially involving the initialization of R (Win32
version has no Rf_initEmbeddedR).
Cheers,
Simon
---
Simon Urbanek
Department of computer oriented statistics and data analysis
Universitätsstr. 14
86135 Augsburg
Germany
Tel: +49-821-598-2236
Fax: +49-821-598-2280
Simon.Urbanek at Math.Uni-Augsburg.de
http://simon.urbanek.info
More information about the R-devel
mailing list