[R-pkg-devel] Package Load fails to find 3rd Party DLL

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Fri Jul 14 21:25:51 CEST 2023


On Fri, 14 Jul 2023 13:29:32 -0400
Russell Almond <russell.g.almond using gmail.com> wrote:

> So I'm confused.  Why is the Makevars -> Makefile conversion assuming 
> that all targets of $(SHLIB) (or all) are executable files, ignoring
> the PHONY declaration?

The $(SHLIB) target is defined in ${R_HOME}/share/make/winshlib.mk. In
particular, it says:

 echo EXPORTS > tmp.def; \
 $(NM) $^ | $(SED) -n $(SYMPAT) $(NM_FILTER) | \
  $(SED) $(ADDQU) >> tmp.def; \

Unfortunately for our case, the $^ automatic variable contains the
names of all prerequisites of the $(SHLIB) target [*], including .PHONY
ones. So as long as $(SHLIB) is declared to depend on NeticaDLL, this
string will get mentioned here.

Maybe it's a red herring. Maybe the message from nm about missing file
has always been harmless, and what we're seeing here is a bug in the
toolchain; perhaps ld.exe doesn't like something about Netica.lib so
much that it crashes. I think that's less likely. If you run the
commands manually but without mentioning NeticaDLL, do you get a DLL in
the end?

> Also, does the example in the Writing R Extensions manual still work?

It should. At the very least, rgl uses the same approach without any
apparent problems:
https://github.com/dmurdoch/rgl/blob/master/src/Makevars.ucrt
(But then it also provides rgl-win.def, which sidesteps the automatic
.def generation, and then has $(OBJECTS), not $^, linked into $(SHLIB).
You may have found a bug in winshlib.mk.)

There's also a different idiom, where all: but not $(SHLIB): depends on
the non-file target:
https://github.com/eddelbuettel/rprotobuf/blob/master/src/Makevars.win
(Not sure how the dependency resolution order is supposed to work in
this case. If winshlib.mk declares that all: depends on $(SHLIB) and
later Makevars declares that all: also depends on winlibs, why doesn't
Make attempt to build $(SHLIB) first, with no regard for winlibs?)

-- 
Best regards,
Ivan

[*]
https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html



More information about the R-package-devel mailing list