Skip to content

SHLIB steps on a Makefile

8 messages · Simon Urbanek, Iago Mosqueira, Brian Ripley +1 more

#
Hi,

I need to create a Makefile.win for a given package so as to fiddle
slightly with the compilation process. My Makefile works fine in Linux
but I am having trouble creating Makefile.win for MinGW. I first
looked at the commands that Rcmd SHLIB appeared to be running and
copied those onto the Makefile. But one step seems to be missing, the
creation of the _res.rc file needed by windres

	g++-sjlj -I$(RHOME)/include -I../inst/include/ -O2 -Wall -c pkg.cpp -o pkg.o
	windres --preprocessor="gcc-sjlj -E -xc -DRC_INVOKED"
-I$(RHOME)/include -I../inst/include -i pkg_res.rc -o pkg_res.o
	g++-sjlj -shared -s -o pkg.dll pkg.def pkg.o FL pkg_res.o -L$(RHOME)/bin -lR

This might be fairly obvious, but it is my first attempt at compiling
with MinGW and my search has been fruitless.

What is it that I need to add to replicate what Rcmd SHLIB does?

Many thanks,


Iago Mosqueira
#
Iago,
On Dec 20, 2007, at 4:49 PM, Iago Mosqueira wrote:

            
If that is the only step you're missing then you have probably missed  
the res.rc rule from MakeDll when creating your Makefile:

$(DLLNAME)_res.rc:
         @PERL5LIB=$(RHOME)/share/perl $(PERL) $(RHOME)/src/gnuwin32/ 
makeDllRes.pl $(DLLNAME) > $@

Cheers,
Simon

PS: Given that you can override any rule, it is usually easier to just  
write your modifications in Makevars[.win] when fiddling with the  
compilation than to replicate the whole process.
#
On Thu, 20 Dec 2007, Iago Mosqueira wrote:

            
That's rather dangerous: we have had lots of trouble with packages for 
which the Makefile works on the maintainer's Linux, but not on other 
people's systems (even Linux ones).

Do you really, really need a Makefile.win?: I would be surprised if you 
did.  Only 9 CRAN packages have a Makefile.win, and two of those are 
dummies and one other we have asked the maintainers to replace by 
Makevars.win as it is not portable.
Adding the resources is not essential: they add identification to the 
DLL which can be very useful but are icing on the cake.  So I would not 
try to emulate that step.

But the Makefile in use is src/gnuwin32/MakeDll and that contains

$(DLLNAME)_res.rc:
         @PERL5LIB=$(RHOME)/share/perl $(PERL) $(RHOME)/src/gnuwin32/makeDllRes.pl $(DLLNAME) > $@

$(DLLNAME)_res.o: $(DLLNAME)_res.rc $(RHOME)/include/Rversion.h
#
On Dec 20, 2007 11:23 PM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
Many thanks for the information. I am trying to make a package C code
compile against a DLL already present in another package, so I need to
include its location in the call to gcc.  I'll see what the most
portable system could be and will test widely.

Regards,


Iago Mosqueira
1 day later
#
Hello,

I have just noticed the Table of Contents of 'Writing R extensions' is 
wrongly numbered, as it gives, for example, 5. Debugging, when that is 
section 4, as the acknowledgements section is numbered in the ToC only.

Regards,


Iago
#
I presume you mean in HTML?  The PDF versions have the correct numbering.
Compare the two versions on http://cran.r-project.org/manuals.html.

That's not a 'typo' but a makeinfo problem.  There's a similar one in the 
TOC of R-admin.texi where the appendices are numbered not lettered in the 
ToC (but the CRAN copy is missing the ToC).

I've not been able to find a makeinfo workaround.
On Fri, 21 Dec 2007, Iago Mosqueira wrote:

            

  
    
#
Hmm, I don't think you need a whole Makefile - while it is a
bit complicated to set locations, etc, essentially if your C code
needs an extra DLL (well, you'll have to bundle it with your package,
etc because the otherwise link-loader won't find it), it is mostly
just in Makevars.win

PGK_LDGLAGS=-lotherlib

'compiling against a DLL in a another package' is alright, but resolving 
the DLL at runtime won't be trivial (unless you set explicit dependency 
of your package against this other one) ; so you might be better off 
compiling against a static build of the other with yours.
Iago Mosqueira wrote:
<snipped>
#
On Sat, 22 Dec 2007, Hin-Tak Leung wrote:

            
There is an interface to ensure that happens: details in 'Writing R 
Extensions'.  The 'live' example is lme4 'LinkingTo' on Matrix and stats.