llvm-gcc-4.2をYosemite (10.10) / El Capitan (10.11)でも使用する方法
Upgrading from command line tools from Xcode 4.6 (or 4.5)
- If you have installed command line tools from Xcode 4.6 (or 4.5), you still have /usr/llvm-gcc-4.2 even after your Macs are upgraded to Yosemite.
-
Installing command line tools (by
xcode-select --install
, required) will install /usr/include, which is used by /usr/bin/llvm-gcc-4.2. You can also have /usr/include/c++/4.2.1 used by /usr/bin/llvm-g++-4.2. - If you want to keep some compatibility, you should not remove /usr/llvm-gcc-4.2.
- The warning
couldn't understand kern.osversion '14.0.0'
can be ignored.
- The warning
New installation
Warn: I have not confirmed if this method works or not.
- Download
Command Line Tools (OS X Mountain Lion) for Xcode - April 2013
from https://developer.apple.com/downloads/ (You need an Apple ID). - Open the dmg and extract Packages/DeveloperToolsCLI.pkg using unpkg.
- Copy usr/llvm-gcc-4.2 to /usr.
- Symlink /usr/llvm-gcc-4.2/bin/ to /usr/bin/.
Anyway
There are yet no ways to have pure gcc-4.2, which has been removed in Xcode 4.3. The effort to maintain it in MacPorts and Homebrew has reached limit (because of upstream license GPLv3).
Additional note
- clang++, which is the official compiler on Mavericks and Yosemite, has an option
-stdlib=libstdc++
.- Using this, you can link your C++ program against libstdc++ instead of libc++.
- Of cource,
-stdlib=libstdc++
cannot be used with-std=c++11
(on OSX) because this libstdc++ is quite old.
- Due to this feature, apple still keeps /usr/include/c++/4.2.1 even in their latest command line tools.
- When they drop this feature, this trick will stop to work.
iostream
- Even this code results in compile error.
#include <iostream>
int main(int argc,char **argv){
std::cout<<1<<std::endl;
}
- To avoid the error, use
llvm-g++-4.2 -mmacosx-version-min=10.7
. - Acknowledgement: http://stackoverflow.com/a/12133504/2641271
El Capitan
- Due to SIP, sadly you cannot have /usr/llvm-gcc-4.2 anymore. But
/Library/SystemMigration/History/Migration-*/QuarantineRoot/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
(or elsewhere as long as inside directory structure is kept) is safe!