clang++ version number from command line?

1,372 views
Skip to first unread message

Daniel Lee

unread,
Nov 5, 2015, 4:05:03 PM11/5/15
to stan-dev mailing list
Anyone know how to get the clang++ version number?

I have mistakenly been using:
clang++ -dumpversion

but that returns 4.2.1 (for gcc compatibility).

Doing the other obvious thing:
clang++ -v

returns:
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

And I'm looking for a way to get the 7.0.0 out of the string.


Anyone know of a good way to do this?



Daniel


Michael Betancourt

unread,
Nov 5, 2015, 4:20:06 PM11/5/15
to stan...@googlegroups.com
Shell command sufficient?

--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Lee

unread,
Nov 5, 2015, 4:21:01 PM11/5/15
to stan-dev mailing list
Yup. We already use sed.

Daniel Lee

unread,
Nov 5, 2015, 4:21:36 PM11/5/15
to stan-dev mailing list
my sed-fu isn't that strong.

Ben Goodrich

unread,
Nov 5, 2015, 4:24:02 PM11/5/15
to stan development mailing list

You could do

${CC} --version | head -n 1 | grep -o -E "[[:digit:]].[[:digit:]].[[:digit:]]" | uniq | sort

which may also work with BSD tools, but the output of version is different on a Mac than on Linux. In other words, I get 3.7.0 rather than 7.0.0.

Ben

 



Daniel


Daniel Lee

unread,
Nov 5, 2015, 4:29:26 PM11/5/15
to stan-dev mailing list
Why 3.7.0? Where does the 3 come from?


Ben Goodrich

unread,
Nov 5, 2015, 4:37:17 PM11/5/15
to stan development mailing list
On Thursday, November 5, 2015 at 4:29:26 PM UTC-5, Daniel Lee wrote:
Why 3.7.0? Where does the 3 come from?

That is the upstream version number

http://llvm.org/releases/download.html#3.7.0

Ben


Michael Betancourt

unread,
Nov 5, 2015, 4:40:21 PM11/5/15
to stan...@googlegroups.com
I think this is going to be a highly system-dependent solution.
On OS X clang++ -v prints to stderr, not stdout, so you have
to do something like

> clang++ -v 2>&1 | head -1 | awk '{print $4}’

Note that this assumes that the out put is always of the form
“Apple LLVM version ____ ()”

Also, the Apple LLVM version is different from the underlying
LLVM version which can make it tricky to compare clang provide
by Apple and other clang versions.

Daniel Lee

unread,
Nov 5, 2015, 4:40:44 PM11/5/15
to stan-dev mailing list
whoa.

The internet is saying to do stuff like:
clang++ -dM -E -x c /dev/null | grep __clang_m

http://stackoverflow.com/questions/19387043/how-can-i-reliably-detect-the-version-of-clang-at-preprocessing-time


This is ridiculous.


Daniel Lee

unread,
Nov 5, 2015, 4:46:59 PM11/5/15
to stan-dev mailing list
On Thu, Nov 5, 2015 at 4:40 PM, Michael Betancourt <betan...@gmail.com> wrote:
I think this is going to be a highly system-dependent solution.
On OS X clang++ -v prints to stderr, not stdout, so you have
to do something like

That explains why I've been having trouble getting sed to work.

 

> clang++ -v 2>&1 | head -1 | awk '{print $4}’

Ok.
 

Note that this assumes that the out put is always of the form
“Apple LLVM version ____ ()”


Yeah... that should be fine for this case.

 

Also, the Apple LLVM version is different from the underlying
LLVM version which can make it tricky to compare clang provide
by Apple and other clang versions.


The reason I'm doing this is because the clang++ version that's shipped out with XCode has changed behavior and is now spitting out unused local typedef warnings.
If I use the flag to squash the warning on an older clang++ (6.x), then it spits out a warning about not recognizing the compiler flag.



Daniel

Daniel Lee

unread,
Nov 5, 2015, 4:57:27 PM11/5/15
to stan-dev mailing list
thanks for helping me out... I think this might work ok:
clang++ -v 2>&1 | grep version | sed 's/.*version \([0-9]*.[0-9]*.[0-9]*\) .*/\1/g'

But it doesn't work for both clang++ and g++

Is that any safer that Michael's solution? Or Ben's?


Daniel

Ben Goodrich

unread,
Nov 5, 2015, 4:59:44 PM11/5/15
to stan development mailing list
On Thursday, November 5, 2015 at 4:46:59 PM UTC-5, Daniel Lee wrote:
The reason I'm doing this is because the clang++ version that's shipped out with XCode has changed behavior and is now spitting out unused local typedef warnings.
If I use the flag to squash the warning on an older clang++ (6.x), then it spits out a warning about not recognizing the compiler flag.

Does passing the -Wno-unused-local-typedefs flag work on older clang++ if you also pass -Qunused-arguments?

Ben


Daniel Lee

unread,
Nov 5, 2015, 5:03:12 PM11/5/15
to stan-dev mailing list
Whoa... that's the first time I'm seeing -Qunused-arguments.

No, it doesn't help.




Daniel Lee

unread,
Nov 5, 2015, 5:04:45 PM11/5/15
to stan-dev mailing list
But this does!

-Wno-unknown-warning-option

Reply all
Reply to author
Forward
0 new messages