Benjamin.STABLER@odot.state.or.us
2003-Sep-17 20:51 UTC
[R] Building and loading a DLL on Windows NT
I am trying to build a simple dll with Rcmd SHLIB to link into R. The results of the build are below. From my limited knowledge of building DLLs, it looks like it worked (I didn't get any errors). F:\R\dlls> Rcmd SHLIB add.C making add.d from add.C g++ -IC:/PROGRA~1/R/src/include -Wall -O2 -c add.C -o add.o ar cr add.a *.o ranlib add.a g++ --shared -s -o add.dll add.def add.a -LC:/PROGRA~1/R/src/gnuwin32 -lg2c -lR Then I tried to load the DLL into R with: dyn.load("F:\\R\\dlls\\add.dll") which returned nothing (which I assumes means there were no errors). But,> is.loaded(symbol.C("add"))[1] FALSE returns false. add is the name of the function in the source file. I know I can dynamically load other DLLs. I've read quite a bit of documentation and I am still stumped. I have all the proper tools for building R under Windows and I know they work since I have built Windows package binaries. Any ideas on what I am doing wrong would be greatly appreciated. Thanks. Ben Stabler
Benjamin.STABLER@odot.state.or.us
2003-Sep-17 21:14 UTC
[R] Building and loading a DLL on Windows NT
Thanks. I didn't try the Borland utility but your response reminded me of a way to view the DLL info in Windows. Right click a DLL and then "quick view" and Windows outputs some file information, including the Export table which lists the names of the symbols in the DLL. The name of the add function is "_Z3addPdS_". So it works now. Thanks for your help. Ben Stabler Oregon Department of Transportation>-----Original Message----- >From: Whit Armstrong [mailto:Whit.Armstrong at tudor.com] >Sent: Wednesday, September 17, 2003 1:56 PM >To: STABLER Benjamin >Subject: RE: [R] Building and loading a DLL on Windows NT > > >There's a free utility from borland (I think it's called tdump >or dump) that >will show you all the exports from a dll. You could run that >on the dll you >made to see what name the function is being exported under >(sorry, but I >don't have the link). Other than that, it looks like you're doing >everything right. I've never built a DLL using SHLIB, so I >can't help you >there. > >Good luck, >Whit > >-----Original Message----- >From: Benjamin.STABLER at odot.state.or.us >[mailto:Benjamin.STABLER at odot.state.or.us] >Sent: Wednesday, September 17, 2003 4:52 PM >To: r-help at stat.math.ethz.ch >Subject: [R] Building and loading a DLL on Windows NT > > >I am trying to build a simple dll with Rcmd SHLIB to link into R. The >results of the build are below. From my limited knowledge of >building DLLs, >it looks like it worked (I didn't get any errors). > >F:\R\dlls> Rcmd SHLIB add.C >making add.d from add.C >g++ -IC:/PROGRA~1/R/src/include -Wall -O2 -c add.C -o add.o >ar cr add.a *.o >ranlib add.a >g++ --shared -s -o add.dll add.def add.a >-LC:/PROGRA~1/R/src/gnuwin32 >-lg2c -lR > >Then I tried to load the DLL into R with: > >dyn.load("F:\\R\\dlls\\add.dll") > >which returned nothing (which I assumes means there were no >errors). But, > >> is.loaded(symbol.C("add")) >[1] FALSE > >returns false. add is the name of the function in the source >file. I know >I can dynamically load other DLLs. I've read quite a bit of >documentation >and I am still stumped. I have all the proper tools for >building R under >Windows and I know they work since I have built Windows >package binaries. >Any ideas on what I am doing wrong would be greatly >appreciated. Thanks. > >Ben Stabler > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Benjamin.STABLER@odot.state.or.us
2003-Sep-18 17:32 UTC
[R] Building and loading a DLL on Windows NT
It was the case sensitive issue. I changed the file from .C to .c and I got the gcc compiler instead of the g++ compiler, which resulted in the function name staying the same. Thanks for your help. Also, I can't seem to find the Borland tdump utility (everything I can find on the Internet says it comes with Borland C++ Builder). All the best, Ben Stabler>-----Original Message----- >From: Whit Armstrong [mailto:Whit.Armstrong at tudor.com] >Sent: Thursday, September 18, 2003 6:01 AM >To: 'Roger.Bivand at nhh.no'; STABLER Benjamin >Subject: RE: [R] Building and loading a DLL on Windows NT > > >One way I've used to get rid of the name mangling is to surround the >function prototypes (or the functions themselves, if you don't >use a header >file) in an export brace: > >export "C" { > int myFunc(int, int) > ... >} > >I'm surprised that SHLIB generates name mangled code. I >thought one of the >advantages of using it was that it produced a clean interface, >especially >since you're using a .c file not a .cpp file. I know that gcc uses >different compilers based on the extension of the file. I >wonder if it's >case sensitive. That is, if you changed the extension to .c >rather than .C >would g++ use the c compiler rather than a cpp compiler. > >Good luck, >Whit
Benjamin.STABLER@odot.state.or.us
2003-Sep-18 17:59 UTC
[R] Building and loading a DLL on Windows NT
Thanks for the link. Turns out I already had pedump though. Ripley's tools for building R for Windows zip file contains a copy of pedump. He also notes it in the readme. I forgot to look at the readme for the R tools when I was debugging my problem. Thanks again to the R community for all its help. Ben Stabler>-----Original Message----- >From: Liaw, Andy [mailto:andy_liaw at merck.com] >Sent: Thursday, September 18, 2003 10:40 AM >To: STABLER Benjamin >Subject: RE: [R] Building and loading a DLL on Windows NT > > >Here's a link to pedump, which BDR has suggested for checking exported >symbols. http://www.simtel.net/product.php?url_fb_product_page=28111. > >HTH, >Andy > >> -----Original Message----- >> From: Benjamin.STABLER at odot.state.or.us >> [mailto:Benjamin.STABLER at odot.state.or.us] >> Sent: Thursday, September 18, 2003 1:32 PM >> To: Whit.Armstrong at tudor.com; Roger.Bivand at nhh.no >> Cc: r-help at stat.math.ethz.ch >> Subject: RE: [R] Building and loading a DLL on Windows NT >> >> >> It was the case sensitive issue. I changed the file from .C >> to .c and I got the gcc compiler instead of the g++ compiler, >> which resulted in the function name staying the same. Thanks >> for your help. Also, I can't seem to find the Borland tdump >> utility (everything I can find on the Internet says it comes >> with Borland C++ Builder). >> >> All the best, >> Ben Stabler >> >> >-----Original Message----- >> >From: Whit Armstrong [mailto:Whit.Armstrong at tudor.com] >> >Sent: Thursday, September 18, 2003 6:01 AM >> >To: 'Roger.Bivand at nhh.no'; STABLER Benjamin >> >Subject: RE: [R] Building and loading a DLL on Windows NT >> > >> > >> >One way I've used to get rid of the name mangling is to >surround the >> >function prototypes (or the functions themselves, if you >don't use a >> >header >> >file) in an export brace: >> > >> >export "C" { >> > int myFunc(int, int) >> > ... >> >} >> > >> >I'm surprised that SHLIB generates name mangled code. I >> >thought one of the >> >advantages of using it was that it produced a clean interface, >> >especially >> >since you're using a .c file not a .cpp file. I know that gcc uses >> >different compilers based on the extension of the file. I >> >wonder if it's >> >case sensitive. That is, if you changed the extension to .c >> >rather than .C >> >would g++ use the c compiler rather than a cpp compiler. >> > >> >Good luck, >> >Whit >> >> ______________________________________________ >> R-help at stat.math.ethz.ch mailing list >> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help >> >