[R-SIG-Mac] Problem with loading compiled code into R
rainer_krug at icloud.com
Wed Apr 12 09:18:41 CEST 2017
I might be completely off, but might it be a problem if R and your library are build using different compiler / versions of compilers?
If this could be the case, you could try to install R from source using home-brew and than compile your library using the same compiler and versions for R.
> On 12 Apr 2017, at 09:08, Hagens, M. (Mathilde) <M.Hagens at uu.nl> wrote:
> Dear all,
> I’ve asked this question on the R-sig-dyn-mod mailing list before and was suggested to post it here as well, so apologies to those of you who’ve seen it before.
> I’m using compiled code (written in C) in combination with the deSolve package to run a one-dimensional reactive transport model in R. On a server I use running on Linux this works flawlessly, but on a MacBook Pro (macOS 10.12.4) I have problems loading the compiled code into R (version 3.3.3, deSolve 1.14).
> The output I get when compiling the code in R using
> system("R CMD SHLIB Model.c”)
> clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c Model.c -o Model.o
> clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o Model.so Model.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
> However, when I try to load the resulting shared object via
> dyn.load(paste("Model", .Platform$dynlib.ext, sep = ""))
> I get:
> Error in dyn.load(paste("Model", .Platform$dynlib.ext, sep = "")) :
> unable to load shared object '/Users/mathilde/Model.so':
> dlopen(/Users/mathilde/Model.so, 6): Symbol not found: _dH_dt
> Referenced from: /Users/mathilde/Model.so
> Expected in: flat namespace
> in /Users/mathilde/Model.so
> The shared object created after compiling seems to look fine. Also, I tried compiling directly from the Terminal, but that doesn’t make a difference. Strangely, when I ran this model on a Mac in the past (~1 year ago) it also worked without problems, leaving me wondering whether it may be due to an R / macOS update. However, switching to an older R version (2.15.2) didn’t solve the issue either. Has anyone experienced similar behaviour and/or knows of a possible solution? I have installed R via the package on one of the CRAN mirrors, and know therefore that it should be compiled using clang, the same compiler I use for compiling the C code. But I am still learning about the compiler flags, perhaps there is something that needs to be changed here?
> Best wishes,
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
More information about the R-SIG-Mac