7

gcc -dumpmachine is almost perfect, but it doesn't respect flags that affect the target. On the other hand, clang does:

$ gcc -dumpmachine
x86_64-unknown-linux-gnu
$ gcc -dumpmachine -m32
x86_64-unknown-linux-gnu
$ clang -dumpmachine
x86_64-unknown-linux-gnu
$ clang -dumpmachine -m32
i386-unknown-linux-gnu
Tavian Barnes
  • 12,477
  • 4
  • 45
  • 118
  • 1
    Probably not, as far as the GCC compiler itself is concerned `-m32` doesn't change the target, just like how `-march=i486` doesn't change the target to `i486-unknown-linux-gnu`. – Ross Ridge Feb 20 '15 at 22:58
  • I think the answer's no. The clang behaviour looks useful though (especially if the `-m32` result honours the `-march` option too, e.g. prints `i686-...` if appropriate) – Jonathan Wakely Feb 20 '15 at 22:58
  • 1
    N.B. `-m32` is not "cross-compiling", it's just using a different instruction set of the same architecture, it's referred to as a multilib target. – Jonathan Wakely Feb 20 '15 at 23:00
  • @JonathanWakely Actually I thought `clang` would do that but it doesn't; even though `-march-armv7-a` will cause its target to change from `armv5te-...` to `arm7-...`, `-dumpmachine` output stays the same. Lame! – Tavian Barnes Feb 20 '15 at 23:04

1 Answers1

4

Perhaps -print-multiarch is useful. According to the documentations, this option "display the target's normalized GNU triplet, used as a component in the library path".

In my box (x86_64) I get:

$ gcc -print-multiarch
x86_64-linux-gnu
$ gcc -print-multiarch -m32
i386-linux-gnu
Grodriguez
  • 21,501
  • 10
  • 63
  • 107