[Rd] How to customize the list of exported functions in a shared library
atp at piskorski.com
Mon Feb 5 15:03:54 CET 2007
On Mon, Feb 05, 2007 at 01:28:24AM -0800, Vladimir Eremeev wrote:
> I am writing binding from C library to R.
> I use R 2.4.1, windows XP, and MinGW.
> R CMD SHLIB -d --output=Rsnns.dll [ list of all C sources]
> R CMD SHLIB -d --output Rsnns.dll Rsnns.c -Wl,-Lc:/mingw/lib,-lfl,-L../sources,-lkernel,-lfunc
You should probably also show us the actual compiler/linker commands
that "R CMD SHLIB" is generating, so we can be sure of what's really
I'm not sure what you may have to do differently with MinGW on Windows
(what linker does that use anyway?), but for comparison, here's how I
do it for R 2.2.1, on Linux (Ubuntu Dapper 6.06), with gcc 4.0.3, and
Gnu ld 2.16.91:
For my own custom R package's C code, my Makefile says:
OBJ = ../foo.o $(patsubst %.c,%.o,$(wildcard ../source/[a-z]*.c))
$(OBJ): %.o: %.c $(HDRS)
R.so: $(OBJ) Makevars vis.map
R CMD SHLIB -o my_pkg_name_R.so $(OBJ)
My Makevars includes this:
PKG_LIBS = -Wl,--version-script=vis.map
And when I build my R package, the R.so make target above generates
this link command:
gcc -shared -o my_pkg_name_R.so [lots of *.o filenames here] -Wl,--version-script=vis.map -L/usr/lib/R/lib -lR
My vis.map file, which uses Gnu ld syntax, looks like this:
That works, my shared library exports ONLY the symbols starting with
"my_pkg_", everything else remains private.
It's the "--version-script" linker option doing the magic. Even with
Gnu ld, there are definitely other ways to control symbol visibility,
but that one seemed most convenient in my case.
Andrew Piskorski <atp at piskorski.com>
More information about the R-devel