From kyleb at metrumrg.com  Thu Jul 28 02:47:29 2016
From: kyleb at metrumrg.com (Kyle Baron)
Date: Wed, 27 Jul 2016 19:47:29 -0500
Subject: [Rd] Creating shared object with BASE in EXPORTS on Windows
Message-ID: <CAJ2Cw8S687CKcCZ3bLfpUFmc2mv-Ct3wUms3s+S0puOhWjYXdA@mail.gmail.com>

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



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