I am writing an R extension that includes C code that relies on a third-party DLL. Compilation is being开发者_如何学Python done on Windows using Rtools with R 2.11.0. My plan is that the DLL will be distributed with the source package and stored in the extension's src directory. My question then is how I can cause the compiler to look in the the src directory when it tries to link to the third-party DLL.
Currently, I am building the package with the command:
R CMD build --binary MyPackage
I also have a file src/Makevars with the following line:
PKG_LIBS = -ldlxapi32
This ensures that the third-party DLL, dlxapi32.dll, is included in compilation. However, the compiler cannot find the DLL, since my package's src directory is not part of the standard library search path.
I have tried to remedy this by changing src/Makevars to read:
PKG_LIBS = -L$(CURDIR) -ldlxapi32
But this fails with output like the following:
gcc -shared -s -static-libgcc -o MyPackage.dll tmp.def dlx.o -L/cygdrive/c/DOCUME~1/abiel/LOCALS~1/Temp/Rbuild709236257/MyPackage/src -ldlxapi32 -Lc:/PROGRA~1/R/R-211~1.0/bin -lR
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: cannot find -ldlxapi32
Here, we can see that $(CURDIR) evaluated to /cygdrive/c.DOCUME~1/... I was hoping that instead it would evaluate to C:/programming/r/MyPackage/src, which is the actual location of the src directory. Is there a way to fix this?
Instead of the overly complicated -L$(CURDIR)
, why don't you just use the equivalent -L.
?
Also, the Rtools suite uses MinGW which is not Cygwin so I'd avoid paths like /cygdrive/c/... as to MinGW this is still c:/....
精彩评论