rClr on Mac ?

Jul 30, 2015 at 5:25 PM
Hi, I'm trying to get rClr working with Mono on a Mac. MY first attempt to install the package in R (after installing and testing the Mono installation) gave the following error before failing:

gcc -std=gnu99 -shared -o rClr.so rClrMono.o -L/usr/lib/pkgconfig/../../lib -lmono-2.0 -lm -lrt -ldl -lpthread -lglib-2.0 -L/usr/lib/R/lib -lR
g++ -std=c++11 -shared -Wl,-z,relro -o rClrMono.so rClrMono.o pkg-config --libs mono-2 glib-2.0 -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
clang: warning: argument unused during compilation: '-pthread'
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [rClrMono] Error 1

Can anyone point me in the right direction ?


Jul 31, 2015 at 1:38 AM
A colleague of mine did run on MacOS a year and a half ago, since then things have changed but it should still be possible.

You may need to adjust one line in the file rClr/src/Makevars.in.
the makefile target on which this fails seems to be:
rClrMono$(SHLIB_EXT): rClrMono.o
    #gcc -std=gnu99 -shared -o rClr.so rClrMono.o -L/usr/lib/pkgconfig/../../lib -lmono-2.0 -lm -lrt -ldl -lpthread -lglib-2.0 -L/usr/lib/R/lib -lR
    $(CXX) -std=c++11 -shared -Wl,-z,relro -o rClrMono$(SHLIB_EXT) rClrMono.o $(ALL_LIBS)
    #$(CXX) -shared -L/usr/lib/R/lib -Wl,-z,relro -o rClr.so rClrMono.o -L/usr/lib/pkgconfig/../../lib -lmono-2.0 -lm -lrt -ldl -lpthread -lglib-2.0 -L/usr/lib/R/lib -lR
the gcc -std=gnu99 etcaetera line you report is not executed (should not be, anyway). $(CXX) -std=c++11 -shared -Wl,-z,relro -o rClrMono$(SHLIB_EXT) rClrMono.o $(ALL_LIBS) is what fails. My understanding is that the option -Wl,-z,relro means that g++ will generate a linker command line ld -z relro etcaetera. man ld tells me this is OK on a Debian box; it seems it is not on MacOS. You may need to change the content of -Wl,-z,relro after reading the manual of ld on Mac. Whether you find a way or not, if you report it in this discussion this would be valuable and appreciated.

This Makefile target has been recently changed to move to c++ and I know it works for recent g++ and Intel C++ compilers on Linux boxes.

Thank you you for your interest in rClr.
Aug 10, 2015 at 10:42 AM
I've now managed to spend some time on this, and have found out:

ld -z relro isn't valid on a Mac. OSX uses the Mach-O format for dlls (dylibs), and the OSX linker generates this by default. So, I just removed that option from the command line.

Now the command
g++ -std=c++11 -shared -Wl -o rClrMono.so rClrMono.o pkg-config --libs mono-2 glib-2.0 -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

gives the error:

ld: warning: ignoring file /Library/Frameworks/Mono.framework/Versions/4.0.2/lib/libglib-2.0.dylib, file was built for i386 which is not the architecture being linked (x86_64): /Library/Frameworks/Mono.framework/Versions/4.0.2/lib/libglib-2.0.dylib

which I believe is telling me that my Mono framework is 32 bit, but I'm compiling and linking rClr for 64bits. This error is also given for libintl and libmono-2.0.

Some further poking around suggests that R on OSX is only available in 64 bit, and so packages need to be built for 64bit, therefore I need a 64bit Mono VM etc.

The Mono packages for the Mac are only available in 32bit. I have downloaded and built 64 bit Mono from source. However, the rClr R package uses the Mono framework installed in /Library/Frameworks by the Mono Mac pkg, which is still 32bit.

Now I'm stuck: Do I try to change the rClr package so it looks for my 64 bit Mono, or do I try to make a 64bit Mono Mac pkg that will install into /Library/Frameworks/
Or wait for the Mono project to produce 64bit packages (currently scheduled for "the future"). Or have I got the above all wrong ?

I'm a bit out of my depth at the moment. I'm happy to dig deeper but would appreciate some thoughts/guidance on the best way to proceed.



PS Thanks for putting the effort into rClr, and making it available. Being able to use R on the Mac to run my .NET code will be truly awesome - no Windows required!