remek
remek

Reputation: 943

Compiling Fortran code for R package under Windows: Undefined reference to REXIT, RWARN, RCHKUSR

I am working on an R package containing Fortran source files. The structure of the Fortran code is rather complex, with many dependencies, therefore I have a Makefile in the src folder for the compilation of the shared library.

So far I have been compiling this package on my machine running Ubuntu 14.04, without any problems. I am now trying to compile it on Windows using Rtools, and I am running into a problem when linking the objects to produce the shared library. More precisely, the linker does not find the functions REXIT, RWARN and RCHKUSR, as I get the following error messages:

undefined reference to `rchkusr_'
undefined reference to `rexit_'
undefined reference to `rwarn_'

These functions are supposed to be in the shared library R.dll (libR.so under Linux). I checked this library with Dependencies Walker and I could find these functions. I have tried to link with -I C:/Program\ Files/R/R-3.1.1/bin/i386/R.dll to make explicit the reference to the shared library. I have tried to recompile with -fno-underscoring to make sure the underscores were not the problem. Nothing helped.

Any ideas where the problem could come from? Any suggestions would be more than welcome!

Under Linux I did not have to do anything special, the linker found the functions without specifying anything in the Makefile.

I am using R version 3.1.1 and Rtools version 3.1.

Many thanks for your help.

Upvotes: 1

Views: 494

Answers (1)

remek
remek

Reputation: 943

After fiddling with the Makefile, I finally found the solution to my problem: The flags I was trying to pass to the linker were wrong. Only the path of the shared library R.dll should be specified, using -L, and the name of the library should be specified using the flag -lR at the end of the command. In short, I specified

gfortran -shared *.o -o myLib.dll -L C:/Program\ Files/R/R-3.1.1/bin/i386 -lR

to create myLib.dll and it worked! I guess I got confused because under Linux there is no need to specify anything, the linker finds the shared library on its own.

Probably not the best and most portable solution I can get (I now have two Makefiles to deal with, Makefile for Linux and Makefile.win for Windows...), but good enough for now.

Upvotes: 1

Related Questions