[Rd] Creating shared object with BASE in EXPORTS on Windows

Kyle Baron
Tue, 02 Aug 2016 04:25:05 -0000

It looks like `BASE` is a keyword in the .def file specification.

https://github.com/bminor/binutils-gdb/blob/master/ld/deffilep.y#L241-L268

For several keywords, I could replicate the syntax error from ld.exe
when the keyword was listed in EXPORTS in the .def file.

As far as I can tell, the dllname-win.def file is a must in this  case
making sure none of the keywords get exported there.


Also:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html


--
Kyle Baron
Metrum Research Group
kyleb at metrumrg.com
www.metrumrg.com


On Wed, Jul 27, 2016 at 7:47 PM, Kyle Baron <kyleb at metrumrg.com>
wrote:
>
> I am building shared objects on Windows system with BASE as a name in
> the shared object.  When BASE appears under EXPORTS in tmp.def file, R
> CMD SHLIB doesn't succeed.  This happens on Windows but not Mac or
> Ubuntu.
>
> Minimal examples:
>
> ////////////////////////////////////////
> This code builds fine
> ////////////////////////////////////////
> void base(int *nin, double *x) {
>   int n = nin[0];
>   int i;
>   for (i=0; i<n; i++) x[i] = x[i] * x[i];
> }
>
> system("R CMD SHLIB foo.c --preclean")
> c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-33~1.1/include"
> -DNDEBUG     -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2
-Wall
> -std=gnu99 -mtune=core2 -c foo.c -o foo.o
> c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o foo.dll
> tmp.def foo.o -Ld:/Compiler/gcc-4.9.3/local330/lib/x64
> -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/x64
> -lR
> ////////////////////////////////////////
>
>
> ////////////////////////////////////////
> Creating shared object from this code
> doesn't succeed
> (error: ld returned 1 exit status)
> ////////////////////////////////////////
> void BASE(int *nin, double *x) {
>   int n = nin[0];
>   int i;
>   for (i=0; i<n; i++) x[i] = x[i] * x[i];
> }
>
>
> system("R CMD SHLIB foo_base.c --preclean")
> c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-33~1.1/include"
> -DNDEBUG     -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2
-Wall
> -std=gnu99 -mtune=core2 -c foo_base.c -o foo_base.o
> c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o foo_base.dll
> tmp.def foo_base.o -Ld:/Compiler/gcc-4.9.3/local330/lib/x64
> -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/x64
> -lR
>
>
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe:
> tmp.def:3: syntax error
>
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe:tmp.def:
> file format not recognized; treating as linker script
>
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/ld.exe:tmp.def:2:
> syntax error
> collect2.exe: error: ld returned 1 exit status
>
> ////////////////////////////////////////
>
>
> I don't personally need to use the BASE name, but my package allows
> users to write code that gets incorporated into a shared object and
> unfortunately BASE is a common name to use in these models.  I'm not
> sure if I should just (somehow) prohibit use of BASE or if there is
> something else not right here.
>
> If there is another solution, I hoping to avoid having to write
> dllname-win.def file on Windows platforms (per
> https://cran.r-project.org/doc/manuals/R-exts.html#Creating-shared-objects)
> ... it worked  but seems that the file needs to be in getwd(), which
> I'd rather not do.
>
> Any insight or advice would be appreciated.
>
> Best Regards,
> Kyle
>
> --
> Kyle Baron
> Metrum Research Group
> kyleb at metrumrg.com
> www.metrumrg.com
>
>
>
> sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets
> [6] methods   base
>
> loaded via a namespace (and not attached):
> [1] tools_3.3.1
>
>
> Rtools33.exe