Re: [Rd] How to customize the list of exported functions in a shared library
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 going on. 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: { global: my_pkg_*; local:*; }; 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 [EMAIL PROTECTED] http://www.piskorski.com/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to customize the list of exported functions in a shared library
Andrew Piskorski wrote: 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 going on. It calls gcc: gcc -I../sources -I. -IC:/PROGRA~1/R/include -gdwarf-2 -Wall -O2 -std=gnu99 -c rsnns.c -o rsnns.o gcc -shared -o Rsnns.dll Rsnns.def [ lots of *.o ] -LC:/PROGRA~1/R/bin -Lc:/mingw/lib -lfl -liberty -lR The file Rsnns.def is generated automatically and is deleted on success. On error, it remains, and contains export of all symbols. Probably GCC generates it, I haven't tracked its generation in the R's scripts. Andrew Piskorski wrote: 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: gcc.EXE (GCC) 3.4.2 (mingw-special) GNU ld version 2.15.91 20040904 Thank you, I'll study this linker option. Andrew Piskorski wrote: 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: { global: my_pkg_*; local:*; }; 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 [EMAIL PROTECTED] http://www.piskorski.com/ -- View this message in context: http://www.nabble.com/How-to-customize-the-list-of-exported-functions-in-a-shared-library-tf3173289.html#a8807456 Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to customize the list of exported functions in a shared library (update)
Vladimir Eremeev wrote: It calls gcc: gcc -I../sources -I. -IC:/PROGRA~1/R/include -gdwarf-2 -Wall -O2 -std=gnu99 -c rsnns.c -o rsnns.o gcc -shared -o Rsnns.dll Rsnns.def [ lots of *.o ] -LC:/PROGRA~1/R/bin -Lc:/mingw/lib -lfl -liberty -lR The file Rsnns.def is generated automatically and is deleted on success. On error, it remains, and contains export of all symbols. Probably GCC generates it, I haven't tracked its generation in the R's scripts. This file is generated in R scripts. MkRules contains %.dll: @$(ECHO) EXPORTS $*.def @$(NM) $^ | $(SED) -n 's/^ [BCDRT] _/ /p' $*.def $(DLL) -shared $(DLLFLAGS) $($*-DLLFLAGS) -o $@ $*.def $^ $($*-DLLLIBS) $(DLLLIBS) @$(RM) $*.def -- View this message in context: http://www.nabble.com/How-to-customize-the-list-of-exported-functions-in-a-shared-library-tf3173289.html#a8807621 Sent from the R devel mailing list archive at Nabble.com. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to customize the list of exported functions in a shared library
It is a bit different on Windows, since it is making a DLL and GNU ld has lots of special-casing for those. To see how to do it, look at the standard package 'stats'. That has a .def file and it works. The naming convention is probably what you missed. (Also, things have changed since R 2.2.1.) On Mon, 5 Feb 2007, Andrew Piskorski wrote: 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 going on. 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: { global: my_pkg_*; local:*; }; 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to customize the list of exported functions in a shared library (update)
On Mon, 5 Feb 2007, Vladimir Eremeev wrote: Vladimir Eremeev wrote: Something important is missing here! It calls gcc: gcc -I../sources -I. -IC:/PROGRA~1/R/include -gdwarf-2 -Wall -O2 -std=gnu99 -c rsnns.c -o rsnns.o gcc -shared -o Rsnns.dll Rsnns.def [ lots of *.o ] -LC:/PROGRA~1/R/bin -Lc:/mingw/lib -lfl -liberty -lR The file Rsnns.def is generated automatically and is deleted on success. On error, it remains, and contains export of all symbols. Probably GCC generates it, I haven't tracked its generation in the R's scripts. Actually, you *still* haven't tracked its generation in the R's scripts. This file is generated in R scripts. MkRules contains %.dll: @$(ECHO) EXPORTS $*.def @$(NM) $^ | $(SED) -n 's/^ [BCDRT] _/ /p' $*.def $(DLL) -shared $(DLLFLAGS) $($*-DLLFLAGS) -o $@ $*.def $^ $($*-DLLLIBS) $(DLLLIBS) @$(RM) $*.def Yes, but that is not necessarily the rule used. See MakeDll which contains the rules for generating DLLs to be linked into R, and CHANGES for the documentation. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel