Is there a gcc option to print the target triplet when cross-compiling?
Asked Answered
B

1

9

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
Berhley answered 13/2, 2015 at 17:45 Comment(4)
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.Artilleryman
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)Powe
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.Powe
@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!Berhley
A
6

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
Angadreme answered 28/1, 2016 at 13:7 Comment(4)
That would be perfect except all it prints on my computer is a single newline :/Berhley
Oops, pity. I learned about the option here: wiki.debian.org/Multiarch/Tuples . Apparently it was integrated upstream in gcc 4.7.Angadreme
-dumpmachine and -print-multiarch technically print different identifiers. -dumpmachine refers to the target machine type that GCC is configured with, canonicalized. -print-multiarch refers to the subdirectory name in the "multiarch" filesystem layout where GCC would find libraries to link to. The main difference are: (1) -dumpmachine are hard-coded when GCC is built, and is not affected by -m32 or -m64 options. (2) -print-multiarch requires a "multiarch"-enabled distro (Debian or Ubuntu), and the identifiers are usually different from the canonicalized machine type.Angular
(2a) "Multiarch" identifier omits the vendor field when it is insignificant (-pc- or -unknown-). (2b) "Multiarch" is bound to ABI, but not to minor revisions of the ISA, therefore i486, i586, i686 and i786 are all covered under the i386 (IA-32) umbrella. Similar for x86-64-v2, x86-64-v3, etc.Angular

© 2022 - 2024 — McMap. All rights reserved.