How to update LLVM and Clang on Mac OS X - xcode

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.

Related

gfortran cannot match MacOS Ventura version

The new MacOS Ventura seems to have broken gfortran MacOS version control. To reproduce my error you only have to do
gfortran --version
And the output is
gfortran: warning: could not understand version ‘13.00.00’
GNU Fortran (GCC) 11.3.0
Copyright (C) 2021 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.
This in itself is just a warning so it might not be a big deal but it breaks "./configure" scripts that require some MacOS versions, e.g. if you try to compile LoopTools you get the following error (in the log file)
arm64-apple-darwin20.0.0-gfortran: warning: could not understand version '13.00.00'
ld: -rpath can only be used when targeting Mac OS X 10.5 or later
collect2: error: ld returned 1 exit status
Since the version cannot be properly read it cannot be compared.
Is there some sort of work around this bug?
I had installed gfortran through conda but aparantly the version is from last year.
I solved it by removing it from conda (had to remove conda entirely due to linking issues) and installed it with brew : brew install gcc.

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.

Mac OS X: Installed and linked gcc 6.2 with Homebrew, but gcc --version still says 4.9.2

On OS X 10.11.6, I installed gcc 6.2.0 using homebrew. It lives over in usr/local/Cellar/gcc/6.2.0/bin. After getting it to link (it didn't do this automagically), I cd there and try the solution from this other thread to create an alias
ln -s gcc-6 gcc
then gcc --version gives me
cc (GCC) 4.9.2 20141029 (prerelease)
Copyright (C) 2014 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.
All this is because trying to install things crashes because of -rdynamic flags, that I hope is fixed in a newer version.
You created the symlink with the proper target name (gcc) but forgot to set the PATH to your newly installed location (or set it after the system path).
What's confusing is that your system already has a version of gcc installed. You have to override the default path so your gcc command comes first.
edit your ~/.profile file and check PATH adjustment. Add a line in the end which contains:
export PATH=/usr/local/Cellar/gcc/6.2.0/bin:$PATH
Then open a new terminal and ensure that which gcc prints
/usr/local/Cellar/gcc/6.2.0/bin/gcc

Matlab mex setup on Mac OS X

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.

Installing Clang on Mac

This is the first time I am working on Mac and I wanted to install the latest version of Clang, so I installed Xcode 5 and Xcode command line tools.
But the Clang version I got from the Xcode (in the terminal, I typed clang --version). It gives me following output:
clang++ --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
I am confused what Clang version it is. I read that the latest Clang is version 3.5. Is the one above similar? (I need complete support for C++11). What is the difference?
Apple uses its own version numbers for Clang and LLVM which correspond with the Xcode version they are bundled with.
The actual Clang version is in indicated by the (based on LLVM X.Xsvn) part. So you have version 3.3, which is the most recent official release as you can see from the LLVM website. That version implements all the major C++11 features as you can see from the C++ support status page.

Resources