RcppArmadillo Compile Errors on OS X Mavericks - xcode

This is a follow-up to the question at Element-Wise Matrix Multiplication in Rcpp
I have been getting a number of different kinds of errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and Command Line Tools installed. Also, gfortran from Homebrew. But I keep encountering the error below --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b)
{ return(a % b); }", depends="RcppArmadillo")
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_18474.so] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include - I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppArmadillo/include" -fPIC "-mtune=native -g -O2 -Wall -pedantic -Wconversion" -c fileaf992bfb8f84.cpp -o fileaf992bfb8f84.o clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o sourceCpp_18474.so fileaf992bfb8f84.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -lgfortran /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install Command Line Tools for XCode (or equivalent).
# Contents of Makevars
$ cat ~/.R/Makevars
CC=clang
CXX=clang++
CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
FLIBS=-lgfortran
Commenting FLIBS=-lgfortran does not help and results in even more error messages --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo")
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_50381.so] Error 1
Thanks in advance.
Update
Following suggestions from response from Kevin and Dirk below, I re-installed Rcpp, RcppArmadillo and inline from source and updated FLIBS to point to the actual directory. This solved the issue.
# Update FLIBS in ~/.R/Makevars
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
#Re-Install from source
install.packages(c("Rcpp","RcppArmadillo","inline"),type="source")
#Restart R

EDIT: If you're a Homebrew user, you now instead need to use brew install gcc (gfortran is no longer provided separate of gcc), and you can then follow the instructions here to get set up.
You have to symlink the libraries to /usr/local/lib manually:
ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/
I thought brew link gfortran would handle this, but apparently it only symlinks the gfortran program and not the actual libraries. So, unfortunately, you have to do it yourself.
(Replace 4.8.2 with whichever version of gfortran you're using from homebrew.)
Alternatively, if you want to keep from modifying /usr/local/lib, you can use
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
in your ~/.R/Makevars file instead, so R knows where to find the gfortran libraries.

I can only suggest you study the numerous threads on the r-sig-mac list, the different answers here on SO as well as the posts on the rcpp-devel list.
As your error comes from the failed Fortran linking, maybe also review the standard page by Simon U. as well as the tools page it points too. AFAIK you should use the (older) gfortran 4.2.* from that page with R -- but then I am not an OS X user.
Edit in late 2016: We now have more detailed instructions in section 2.16 of the Rcpp FAQ.

Related

gcc compile, getting "clang: error: unsupported option '-fopenmp'"

I am running the command
gcc -o openmptest -fopenmp openmptest.c
however am getting the error:
clang: error: unsupported option '-fopenmp'
I am running this on Mac Mojave. In addition I am using VS code which is telling me
cannot open source file "omp.h"
for my include statement.
I think it could work if you install libomp by
brew install libomp
and then,
clang -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp openmptest.c -o main
This should work, I was having the same issue and and managed to compile my code by using the above.

ld: framework not found Python

I am trying to install a python module (SPArse Modeling Software) but the install script doesn't seem to be able to find the system's default Python.framework. This is an almost new (no migration assistant) Mac OS 10.9.5 system with both the default system python and Anaconda installed. I briefly installed Enthought Canopy but removed it when I decided to go with Anaconda. /System/Library/Frameworks/Python.framework exists and seems to have all the files you would expect.
In terminal, this is what happens:
bash-3.2$ which python
//anaconda/bin/python
bash-3.2$ cd spams-python
bash-3.2$ python setup.py build
running build
running build_py
running build_ext
building '_spams_wrap' extension
gcc -fno-strict-aliasing -I//anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -Ispams/linalg -Ispams/prox -Ispams/decomp -Ispams/dictLearn -I//anaconda/lib/python2.7/site-packages/numpy/core/include -I/usr/include/python2.7/ -I//anaconda/include/python2.7 -c spams_wrap.cpp -o build/temp.macosx-10.5-x86_64-2.7/spams_wrap.o -DNDEBUG -DUSE_BLAS_LIB -fPIC -fopenmp -m32
clang: warning: argument unused during compilation: '-fopenmp'
#Omitting some irrelevant (I think) warnings#
4 warnings generated.
gcc -bundle -undefined dynamic_lookup -L//anaconda/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/spams_wrap.o -L//anaconda/lib -lstdc++ -lblas -llapack -o build/lib.macosx-10.5-x86_64-2.7/_spams_wrap.so -m32 -framework Python
ld: framework not found Python
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1
So, my question is, is my diagnosis of the problem correct? How can I tell GCC where Python.framework is? Is there some environment variable that isn't set correctly?
The Anaconda Python is not a Framework build of Python. If the module expects that it's not going to work. Commenting out commenting out "'-framework', 'Python'" in setup.py sounds like a good start, and if it works, then it probably is the right solution.
Compile it with gcc-5, and I successed.

Building numpy/scipy for Python3 on Mac OS Lion

I can't get Numpy or Scipy to work with Python3 on MAC OSX Lion.
I have used pip successfully to install numpy, scipy and matplotlib, and they work well with Python2.7, but in Python3 typing import numpy brings up No module named numpy. I've tried downloading the source code directly and then running 'python3 setup.py build', but I get various error warnings, some in red that have to do with fortran (e.g. 'Could not locate executable f95'). The error message that appears to fail in the end is 'RuntimeError: Broken toolchain: cannot link a simple C program', and appears to be related to the previous line 'sh: gcc-4.2: command not found'.
The Scipy website suggests that there may be issues with the c compiler, but the same problems didn't arise using pip to install for python2.7. I have followed the instructions on the website regarding changing the compiler but this has not made any difference.
I have also tried installing from a virtual environment:
mkvirtualenv -p python3.2 test1
pip install numpy
But this fails with Command python setup.py egg_info failed with error code 1 in /Users/Eddy/.virtualenvs/test1/build/numpy
I've considered making python3 default, and then I thought a pip install might work, but I don't know how to do that. Does anyone have any suggestions for how I might proceed? Thanks.
I ran into the same issue of
scipy/sparse/linalg/dsolve/superlumodule.c:268:9: error: non-void function 'PyInit_superlu' should return a value [-Wreturn-type]
someone on the scipy mailing list suggested the following:
what happens if you change the line 268 ( in scipy/sparse/linalg/dsolve/_superlumodule.c)
from
return;
to
return NULL;
sure enough it worked
I've made some progress with this problem, with much assistance from Ned Deily on the pythonmac mailing list. I can now build numpy for python3, but scipy still won't build.
To install numpy:
The scipy website (http://www.scipy.org/Installing_SciPy/Mac_OS_X) suggests working around the C compiler problem with three typed commands, but these are insufficient, you need one more:
$ export CC=clang
$ export CXX=clang
$ export FFLAGS=-ff2c
$ export LDSHARED='clang -bundle -undefined dynamic_lookup \
-arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -g'
After this building from source should work. See here for details.
Problem building scipy:
I don't know what the issue here is, something with the C compiler again though I think. Here are the error messages. I'd greatly appreciate any thoughts on this matter.
Thanks, Eddy
error messages:
compiling C sources
C compiler: clang -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk
compile options: '-DNO_ATLAS_INFO=3 -DUSE_VENDOR_BLAS=1 -I/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c'
extra options: '-msse3'
clang: scipy/sparse/linalg/dsolve/_superlumodule.c
In file included from scipy/sparse/linalg/dsolve/_superlumodule.c:18:
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/arrayobject.h:15:
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarraytypes.h:1972:
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API"
^
scipy/sparse/linalg/dsolve/_superlumodule.c:268:9: error: non-void function 'PyInit__superlu' should return a value [-Wreturn-type]
return;
^
1 warning and 1 error generated.
In file included from scipy/sparse/linalg/dsolve/_superlumodule.c:18:
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/arrayobject.h:15:
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarrayobject.h:17:
In file included from /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/ndarraytypes.h:1972:
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API" [-W#warnings]
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API"
^
scipy/sparse/linalg/dsolve/_superlumodule.c:268:9: error: non-void function 'PyInit__superlu' should return a value [-Wreturn-type]
return;
^
1 warning and 1 error generated.
error: Command "clang -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -DNO_ATLAS_INFO=3 -DUSE_VENDOR_BLAS=1 -I/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c scipy/sparse/linalg/dsolve/_superlumodule.c -o build/temp.macosx-10.6-intel-3.2/scipy/sparse/linalg/dsolve/_superlumodule.o -msse3" failed with exit status 1
I had this problem and one of these sorted it - not sure which one but I include both for completeness:
I had this in my .bash_profile "export CC=gcc-4.2" which was probably some kind of hack from previous OS X compilation problems, I removed it.
Installed the standalone GCC from here https://github.com/kennethreitz/osx-gcc-installer/ over my XCode install
booted up a new terminal window and pip install numpy worked fine

Problems installing Haskell library regex-pcre on Mac OS X

I'm trying to install the Haskell regex-pcre library using:
cabal install --extra-include-dirs=/usr/local/include \
--extra-include-dirs=/usr/include regex-pcre
However I get this weird error:
Resolving dependencies...
Configuring regex-pcre-0.94.2...
Preprocessing library regex-pcre-0.94.2...
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/HsFFI.h:68,
from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:4,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/float.h:8:24: error: float.h: No such file or directory
In file included from /Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/template-hsc.h:9,
from dist/build/Text/Regex/PCRE/Wrap_hsc_make.c:1:
/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
compiling dist/build/Text/Regex/PCRE/Wrap_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Text/Regex/PCRE/Wrap_hsc_make.c -o dist/build/Text/Regex/PCRE/Wrap_hsc_make.o -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -fno-stack-protector -march=i686 -m32 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -D__GLASGOW_HASKELL__=700 -Ddarwin_BUILD_OS -Ddarwin_HOST_OS -Di386_BUILD_ARCH -Di386_HOST_ARCH -I/usr/include -I/usr/local/include -DHAVE_PCRE_H -DSPLIT_BASE=1 -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/bytestring-0.9.1.10/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/base-4.3.1.0/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include -I/Library/Frameworks/GHC.framework/Versions/7.0.2-i386/usr/lib/ghc-7.0.2/include/
cabal: Error: some packages failed to install:
regex-pcre-0.94.2 failed during the building phase. The exception was:
ExitFailure 1
The gist of it, seems to be that it can't find a second float.h file:
/usr/include/float.h:8:24: error: float.h: No such file or directory
I've opened /usr/include/float.h and line 8 reads:
#include_next <float.h>
I've done my searching on Google, and although I don't know that much C I think I understand what that line is supposed to say, but... I don't know how to really solve this problem. I don't know where else I have a float.h file on my system.
The GHC and GCC versions I'm using. GCC comes from XCode 4. GHC is 32bit, but I've tried the 64bit version too, with the same results.
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.2
OS X version is 10.6.7.
Any help greatly appreciated.
Looks to me like ticket #5011 - XCode 4 on Mac + GHC 7.0.2 fails to link.
This is fixed in GHC 7.0.3 which will be part of the mid-April release of the Haskell Platform.
And alternative fix is to downgrade to the 2010.2 Haskell Platform.
See this question yesterday: Can't install OpenGLRaw-1.1.0.1 on OS X

Compiling C code for 64-bit Matlab on Intel MAC

I need compile a piece of C code to be called from matlab (mex compiling).
I am doing that on an intel mac and, since I am using Matlab's R2010a (7.10.0.499), I'd like to compile the C code into a version for 64-bits.
For whatever reason, just doing mex with the -arch=maci64 option did not seem to work...
As a way around, I am compiling the C code to a mexmaci64 file directly on the command line.
I used the gcc calls made by mex (with the -v option on) as a starting point.
I managed to compile the C code to an object file, but it looks like I am not compiling the C code to the correct architecture.
Does anyone know how to correct the gcc calls below so the C code gets compiled to 64-bits intel macs?
Details are listed below.
As always, any help greatly appreciated...
Keep thirsty, my friends. :p
G
DETAILS:
Here is how I did the compilation and linking:
gcc -c -I/Applications/MATLAB_R2010a.app/extern/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -fexceptions -D MACVERSION -DMX_COMPAT_32 -O3 -DNDEBUG "BoxQP.c"
gcc -O -bundle -Wl,-flat_namespace -undefined suppress -Wl,-exported_symbols_list,/Applications/MATLAB_R2010a.app/extern/lib/maci64/mexFunction.map -o "BoxQP.mexmaci64" BoxQP.o -L/Applications/MATLAB_R2010a.app/bin/maci64 -lmx -lmex -lmat -lstdc++
Here are the warnings I get:
ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmx.dylib, file is not of required architecture
ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmex.dylib, file is not of required architecture
ld warning: in /Applications/MATLAB_R2010a.app/bin/maci64/libmat.dylib, file is not of required architecture
Ignoring the warnings and calling the BoxQP function from matlab results in the following error message:
??? Invalid MEX-file '/Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64':
dlopen(/Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64, 1): no suitable image found.
Did find: /Users/gvrocha/Documents/academic/projects/splice/code/matlab/covsel/BoxQP.mexmaci64: mach-o, but wrong architecture.
PS: I tried changing the -DMX_COMPAT_32 flag to -DMX_COMPAT_64 but I do get the same warnings and same error...
PPS: I guess it may be relevant to mention that I am using Mac OS X 10.5.8 (the "tropical"/plain-vanilla Leopard, i.e., not the snow Leopard).
PPPS: The same happens with the yprime.c example provided by MATLAB

Resources