Skip to content

cblas on Mac and Linux

5 messages · Brian Ripley, Kasper Daniel Hansen, Simon Urbanek +1 more

#
Hi,

I've got a package with some C code calling cblas functions (e.g., 
cblas_dgemm). The code is called using .C() . In order to compile 
correctly either cblas.h on Linux or Accelerate.h on a Mac:

#include <R.h>
#ifdef MACOSX
#include <Accelerate/Accelerate.h>
#else
#include <cblas.h>
#endif

Of course, this doesn't work well with the standard Makevars 
PKG_LIBS=$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) since I need to set the 
-DMACOSX flag for each platform.

Do I need to create another makefile to decide which OS the code is 
running on, or is there an easier way of doing this?

Thanks,
Gad
#
On Fri, 20 Mar 2009, Gad Abraham wrote:

            
You use configure -- see 'Wrtiing R Extensions' --  to fill in a 
Makevars.in.  But beware that in general $(BLAS_LIBS does not contain 
a cblas, even on MacOS X, so if portability is any sort of issue, you 
need to set PKG_LIBS via configure too.

  
    
#
There are Apple specific defines in GCC. As far as I know
__APPLE__
means compiling on Apple hardware, whereas
__APPLE_CC__
means compiling using an Apple supplied compiler.

However, the first one seems sometimes to be used when the last one is  
intended.

Kasper
On Mar 19, 2009, at 21:50 , Gad Abraham wrote:

            
#
On Mar 20, 2009, at 13:14 , Kasper Daniel Hansen wrote:

            
Note, however, that as Brian suggested neither of the above helps with  
the case under consideration if it is to be portable. Although  
Accelerate can be assumed on (recent) OS X, it doesn't mean that it's  
what R uses or the user wants. In fact BLAS headers are not always  
available, so in most cases the problem listed here is not an issue at  
all since the functions used can be simply declared. The real issue is  
linking against the correct library and R provides no way to do that  
automatically since it doesn't use cblas, so the only reliable way is  
what Brian described.

Cheers,
Simon
2 days later
#
Simon Urbanek wrote:
Thanks to Prof Ripley, Kasper, and Simon.