I want to understand which version of clang Apple installed in my macbook, to see with c++11 and/or c++14 features are available.
I typed this command:
clang --version
//----response
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
But I am not able to understand what (clang-700.1.76)
mean.
How can I convert this code to a clang version?
This is the site where you could check c++ features available in clang version http://clang.llvm.org/cxx_status.html
The (Apple) version number of the compiler is mostly useless, since you also need to consider whether your code is compiled with libstdc++
or with libc++
(or any other standard library) - and which version of those.
If you want to test for language or library features, it is better to check other defined values, e.g., __cplusplus
, __cpp_constexpr
, __cpp_variadic_templates
, etc. It is not perfect, but it seems to work better (if you want portability) in my experience and the support from all major compiler is improving.
Each C++ standard version defines a value for __cplusplus
, some compilers use intermediate values to say "we already started on C++14, but we are not there yet". Use >=
to test when needed.
The other feature test macros are similar, you can find the current version at N4440. Not all compilers implement N4440, though.
Here is the best listing I've found that correlates Apple's clang versions with the LLVM versions:
https://trac.macports.org/wiki/XcodeVersionInfo
Previous versions used to say what LLVM version they corresponded to, but starting with 7.0, Apple decided to no longer do that. They even define the __clang_version__
and related preprocessor macros to indicate the Apple version number, not the LLVM version. So they're useless for this as well.
Unfortunately, it looks like the only way to see if you have a feature is to try it and check if it works. e.g. 7.0.2 still doesn't have OpenMP enabled by default (although it's enable-able), so I guess it's still 3.6, not 3.7 yet.
As hinted by pkolbus
, you can look at the /src/CMakeLists.txt
to guess the corresponding Clang version. For example, Apple Clang 800.0.38 and 800.0.42.1 both seem to based on Clang 3.9.0 according to
if(NOT DEFINED LLVM_VERSION_MAJOR)
set(LLVM_VERSION_MAJOR 3)
endif()
if(NOT DEFINED LLVM_VERSION_MINOR)
set(LLVM_VERSION_MINOR 9)
endif()
if(NOT DEFINED LLVM_VERSION_PATCH)
set(LLVM_VERSION_PATCH 0)
endif()
if(NOT DEFINED LLVM_VERSION_SUFFIX)
set(LLVM_VERSION_SUFFIX svn)
endif()
Wikipedia's Xcode page has a map of Apple to LLVM versions (up until at least AppleClang 800.0.42.1). The LLVM column has the open-source LLVM/Clang version. From this you can look up a language feature in cppreference's chart of compiler support for language features.
One can try to compile some file with --verbose option.
For example:
c++ --verbose -c test1.cpp
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test1.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.9 -v -dwarf-column-info -coverage-file /Users/az/ctest/test1.cpp -resource-dir /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.0.2 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/az/ctest -ferror-limit 19 -fmessage-length 130 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o test1.o -x c++ test1.cpp
clang -cc1 version 7.0.2 based upon LLVM 3.7.0svn default target x86_64-apple-darwin14.5.0
It does print LLVM svn version (3.7.0 in our example)
If you use the strings command on the compiler you might get the LLVM version.
For example if you have the clang version that identifies itself as Apple LLVM version 7.0.2 (clang-700.1.81), the output of strings will have this value:
LLVM 3.7.0svn
This doesn't appear to work with version Apple LLVM version 7.3.0 (clang-703.0.29)