Matlab mex setup on Mac OS X - macos

I'm trying to setup mex with Matlab R2013a on my Mac. The following are the compilers I have on the machine (through Xcode I believe). How can I update the compiler and configure the mex setup?
fadama:[~]$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx- include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
fadama:[~]$ llvm-gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I was able to finally setup the mex.
When I try compiling the sample code from "Accelerating Matlab with GPUs. A Primer with Examples", I get the following errors:
>> system('nvcc -c AddVectors.cu')
clang: error: unsupported option '-dumpspecs'
clang: error: no input files
ans =
1
Please help. I'm on a Mac with updated Xcode.
Thank you in advance.

Related

Why can't I change gcc compiler from 4.2.1 to later version?

I've tried to replace the included gcc 4.2.1 compiler on my Mac Book Pro with latest version of Mac OSX but can't figure out what Im doing wrong:
Also this screen scrape from my shell doesn't make sense for me:
Johans-MBP:bin johanlindfors$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Johans-MBP:bin johanlindfors$ which gcc
/usr/local/bin/gcc
Johans-MBP:bin johanlindfors$ /usr/local/bin/gcc --version
gcc (Homebrew GCC 8.2.0) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Johans-MBP:bin johanlindfors$
It's because it's actually Apple Clang pretending to be GCC.
The system gcc-4.2.1 compiler is a (very old) legacy of the migration from the gcc to clang compilers. It should never be used for your own code. Edit your .profile or .tcshrc to prepend the newer gcc directory to the path. Or save a lot of time and energy and use MacPorts.
Unfortunately, Clang has established 'absolute' compatibility at gcc-4.2.1: see: clang -E -dM - < /dev/null | grep GNU
That's not a bad thing. Once the compiler gains traction it's going to provide it's own extensions, and no longer track those of others. Many extensions remain compatible like Intel's <x86intrin.h>. It's not really in either compiler's interests to provide too much divergence with extensions...
The 'stable' gcc is now 8.2.0 according to MacPorts. The stable MacPorts clang (which irritably conflicts with OS X) is apparently 7.0.0 ... short story - don't go replacing sets of files arbitrarily that you think might work. Then set up paths correctly - IIRC, MacPorts will do this for you.
I provided a more recent summary: here.

Unable to upgrade cmake from 2.6 to higher

I am using centos 6.5 which has a cmake 2.6.
I want to upgrade to higher version (cmake 2.8 or cmake 3.0).
I have the downloaded the setup files.
When i run the file using ./configure i get the following error message
[root#dtl-sameet cmake-3.0.0]# ./configure
---------------------------------------------
CMake 3.0.0, Copyright 2000-2014 Kitware, Inc.
C compiler on this system is: gcc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /home/sameet/Downloads/cmake-3.0.0/Bootstrap.cmk/cmake_bootstrap.log
I have updated the gcc to higher version and i want to keep this higher version
[root#dtl-sameet cmake-3.0.0]# gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root#dtl-sameet cmake-3.0.0]# g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The link answers the similar question but i did not wanted to install "Development Tools" as this would make gcc fall back to old version.
This link answers the similar question but i did not wanted install a package manager.
I set the environmental variable for CXX as
export CXX="/usr/bin/gcc"
It did not work.
Look into Bootstrap.cmk/cmake_bootstrap.log.
The configure script runs a number of tests. I assume that one of them failed.
You need to find out which one, what the test does and how to make it work or disable it.
You might want to update your question and hopefully someone will find out what is wrong with the cmake bootstrap on your system.

Trouble installing PETSc on Mac OS X

I'm trying to install the PETSc scientific computation library on Mac OS X 10.6.8.
When configuring the project, I am running into the following error message:
cls ~/Downloads/petsc-3.2-p6 $ ./configure
===============================================================================
Configuring PETSc to compile on your system
===============================================================================
TESTING: checkFortranNameMangling from config.compilers(config/BuildSystem/config/compilers.py:589) *******************************************************************************
UNABLE to CONFIGURE with GIVEN OPTIONS (see configure.log for details):
-------------------------------------------------------------------------------
Unknown Fortran name mangling: Are you sure the C and Fortran compilers are compatible?
Perhaps one is 64 bit and one is 32 bit?
See http://www.mcs.anl.gov/petsc/petsc-as/documentation/faq.html#gfortran
*******************************************************************************
I have the following versions gcc
cls ~/Downloads/petsc-3.2-p6 $ gcc --version
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
Copyright (C) 2007 Free Software Foundation, Inc.
and gfortran
cls ~/Downloads/petsc-3.2-p6 $ gfortran --version
GNU Fortran (GCC) 4.2.3
Copyright (C) 2007 Free Software Foundation, Inc.
Why are those not compatible?
It seems that the two compilers come from two different packages. Maybe you should show us where do their binary reside, for example by using which gcc and which gfortran. Try to find accompanying build of gfortran to your build of gcc, which comes from LLVM. Your gfortran is probably not provided by LLVM, but it is normal gcc build. The installer suggests that they may even be 32 and 64 bit.

CUDA SDK issues with gcc/g++: old version of gcc can't find old version of g++?

I'm installing CUDA on F15. I'm well aware of the fact CUDA needs older versions gcc/g++ and I've installed gcc/g++ 4.5.1, and softlinked them as documented here. I no longer get the error mentioned in that post...however, when I tried compiling the SDK, I get the following error:
make[1]: Entering directory `/home/whao/NVIDIA_GPU_Computing_SDK/C/src/bilateralFilter'
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
make[1]: *** [obj/x86_64/release/filter_kernel.cu.o] Error 1
I suspect that somehow, the older version of g++ in question isn't being recognized? For what it's worth, consider the following two outputs:
[whao#gen-whao-cuda C]$ /usr/local/cuda/bin/gcc --version
gcc (GCC) 4.5.1 20101130 (Red Hat 4.5.1-6)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[whao#gen-whao-cuda C]$ /usr/local/cuda/bin/g++ --version
g++ (GCC) 4.5.1 20101130 (Red Hat 4.5.1-6)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
There is a file named host_config.h where gcc version is checked (the path is /usr/local/cuda/include). You can comment out the appropriate if part (if gcc_version>4.5.* ....). gcc 4.5 may be supported in toolkit 4.1 but if this lines remain, there always be an error before even start compiling.

How to update LLVM and Clang on Mac OS X

On my version of Mac OS X (10.7.1 (Lion) and Xcode 4.1), there is LLVM 3.0svn and Clang 2.1.
The current versions are LLVM 3.0 and Clang 3.0.
From the Xcode web site, it seems that the latest version (4.2.1) still uses LLVM 2.0, and this seems to be a mistake.
If installing the latest Xcode, will I get a more recent version of LLVM/Clang?
Are there any possible issues installing Clang manually?
Once installed, will the new Clang be used automatically by all the IDEs I have (e.g., NetBeans)?
The web site is incorrect. Xcode 4.2.1 and 4.2 include LLVM 3.0 and Clang 3.0:
clang --version
Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
clang++ --version
Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
llvm-g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
llvm-gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
You can comfortably build your own LLVM using Homebrew:
brew install llvm
There are also versioned packages in case you need a specific version:
llvm#3.7
llvm#3.8
llvm#3.9
llvm#4
Software vendors are traditionally conservative about updating build tools and with good reason. If you want to use the latest publicly-supported versions of build tools supplied and modified by Apple, you should stick to those in the latest version of Xcode for the OS X release you are running.
There are usually good reasons why Apple has not yet updated to the latest cutting-edge versions of open source components, like serious bugs.
If you don't need the Apple-supplied modifications and don't mind living on the edge - i.e., no support from Apple and possibly (re-)discovering known problems - and are not planning to ship compiled files to other people's systems, you could install your own versions in, say, /usr/local/bin or by using third-party package managers, like MacPorts http://www.macports.org/ports.php?by=name&substr=clang). You should definitely not try to replace the files at the paths installed by Xcode.
Is it worth it? Only you can decide that.
I highly recommend against replacing the system compiler on macOS:
Many build processes you will see (e.g. Xcode) rely on Apple-specific extensions. For example, last I checked Apple have their own linker.
Also, Linuxes do not enforce binary compatibility -- generally, people build software from source, or download specific binaries for each operating system version. As an end-user (as opposed to developer/professional user) operating system, macOS goes to great effort to maintain compatibility with binaries built on older macOS versions.
Replacing the compiler, or worse, system libraries, will break these compatibility guarantees. It may also break your system in subtle, non-obvious ways.
But feel free to install a second copy of clang in /usr/local or so and explore new features, but leave the system compiler alone.
Also note that Apple do not support submitting software to the app stores that aren't built with Xcode and the compiler it includes. While you may go unnoticed if you do that, you may get rejected during app store review if your compiler fails to do anything that Apple's compiler does.
On 10.8.2 (Mountain Lion) with Xcode 4.6, the versions are:
$ clang --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
$ clang++ --version
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
$ llvm-g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ llvm-gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You can update Xcode for Lion too from the App Store or Apple Developer Account direct download, and install the command line tools, which will update Clang and LLVM to the above versions.
OS X Update version 10.9.2 (Mavericks) brings Xcode to version 5.1 (5B130a), and Clang to the latest stable (for OS X):
clang --version
Output:
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
On my Mac, llvm-gcc and llvm-g++ are symbolic link to this Clang:
lrwxr-xr-x 1 root wheel 5B 25 Oct 16:48 /usr/bin/llvm-gcc -> clang
lrwxr-xr-x 1 root wheel 7B 25 Oct 16:48 /usr/bin/llvm-g++ -> clang++
My latest R installation is configured to use llvm-gcc-4.2 which would cause error when building SHLIB. Creating symbolic links for llvm-gcc-4.2 and llvm-g++-4.2 the same way, instead of replacing LLVM or CLANG, is enough to resolve the errors.

Resources