Why did installing Xcode command line tools change what 'gcc --version' reports

早过忘川 提交于 2020-01-22 13:37:44

问题


Recently I updated Xcode on OS 10.9 to version 5.0.1 through the AppStore. It appeared to me that this update also updated command line tools, for example running gcc --version produced

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

However answers here on SE indicate that this is not the case and that command line tools need to be downloaded and installed separately. I did this and ended up with the same tool versions, but with subtle differences. For example, now running running gcc --version produces

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.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

Is this how things are supposed to work — does this represent the expected behavior for current Xcode command line tools or is it peculiar to an installation via direct download (vs. installing along with Xcode through the AppStore; if that's even possible)?

And what's the significance of the change from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1 to /usr/include/c++/4.2.1?


回答1:


I'll structure my answer with a list so that you get the full picture, the answer to your main question being concluded in the last list item:

  • Since Mavericks, the default compiler suite has been Clang/LLVM instead of GNU GCC. Synonyms for gcc and g++ that point to Clang and Clang++ respectively have been kept in order to preserve backwards compatibility and since Clang is very much backwards compatible with GCC, there's no reason not to do so.
  • Since XCode 6 I think, XCode automatically bundles the command line developer tools in the main install and .app bundle for XCode. Same goes for default frameworks and toolkits. Full command line development is still not fully operational at this point, just enabled XCode development.
  • However, in order to successfully do development at the command line one has to execute xcode-select --install in the Terminal app and follow the instructions.
  • Given that the SDK's are now bundled and organized in a directory structure inside XCode.app bundle, the change in gxx-include-dir you noticed is due to the fact that now, /usr/include is merely a soft link now to the proper place for the specific includes:

    $ls -l /usr/include

    lrwxr-xr-x 1 root wheel 112 Feb 2 19:08 /usr/include -> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/

The last point, is not necessarily a bad thing and xcode-select(1) command can now be used to manage the active SDK. I hope this clarifies things a bit for those confused, since all these (quite big) changes were rolled out in classic Apple fashion, in complete and utter silence.



来源:https://stackoverflow.com/questions/19623124/why-did-installing-xcode-command-line-tools-change-what-gcc-version-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!