14

I try to find out the triplet for my device, because i try to cross compile, but there is no gcc installed on the target device and i am not allowed to install it.

With gcc installed i could just write gcc -dumpmachine

Is it possible to find this information without gcc?

Black
  • 1,989
  • 7
  • 28
  • 58
  • 1
    how far will `uname -a` get you here? – FelixJN Aug 25 '15 at 11:59
  • 1
    i get `Linux MyDeviceName 2.6.35.3-571-gcca29a0-g8b63513-dirty #162 PREEMPT Tue Aug 4 10:57:29 CEST 2015 armv5tejl GNU/Linux` – Black Aug 25 '15 at 12:09
  • 1
    Can you tell us the manufacturer and model of the target device, for example `Freescale MX28EVK` ? – Mark Plotnick Aug 25 '15 at 12:15
  • No i can't, its a small special device with a metal housing and nothing written on it. – Black Aug 25 '15 at 12:21
  • 1
    So you have a `armv5tejl` core, `GNU/Linux` as OS, and if you really need the vendor, too, try `lshw -class cpu` and ignore the "should be run as super-user" part. – FelixJN Aug 25 '15 at 12:23
  • @Fiximan thx for your answer, unfortunattely i get `-sh: lshw: not found`, but i think i can just write `unknown` at the vendor part. – Black Aug 25 '15 at 12:25
  • @Fiximan The precise CPU model isn't relevant here. The exact role of the “vendor” part of the triplet is somewhat variable; here what matters is which ABI (e.g. for ARM there's little-endian vs big-endian, soft vs hard float, ...). – Gilles 'SO- stop being evil' Aug 25 '15 at 23:05
  • check also http://askubuntu.com/questions/872457/how-to-determine-the-host-multi-arch-default-folder – Bernardo Ramos Jan 17 '17 at 22:17

3 Answers3

14

You can get a lot of information by means of uname and also by checking with file the type of executables:

$ gcc -dumpmachine
x86_64-linux-gnu
$ uname -o -m
x86_64 GNU/Linux
$ file /usr/bin/file
/usr/bin/file: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=d8ac02806880576708bf189c064fca78ea89f1d0, stripped

If your device doesn't have file installed, copy a binary executable from it to another Linux computer and run file there.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
planetmaker
  • 461
  • 3
  • 13
  • Thank you for your answer. Where can i find a binary executable? Under /usr/bin ? Sorry, im pretty much beginner, so an example would be great. – Black Aug 26 '15 at 06:18
  • 1
    If you got the file command as shown in the snippet above you can use it itself as executable example. Otherwise any other file in /usr/bin should do. – planetmaker Aug 26 '15 at 06:54
  • uname -o -m gives `armv7l GNU/Linux` instead of `arm-linux-gnueabihf` – Fuseteam May 26 '21 at 01:01
5

You'll need to find files in the file system which preserve the triplet passed to / probed by configure on the build time of your target userland.

In common GNU/Linux distributions the best bet would be querying to common command binaries like bash curl make svn. In the following example on Debian/armhf (QEMU image taken from here) I got the canonical triplet arm-unknown-linux-gnueabihf by bash --version. So it would be basically safe to configure my cross toolchain for this system by /path/to/configure --target=arm-unknown-linux-gnueabihf.

root@debian-armhf:~# bash --version
GNU bash, version 4.2.37(1)-release (arm-unknown-linux-gnueabihf)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

There's no reliable way to know non-canonical triplet like arm-linux-gnueabihf x86_64-linux-gnu from the userland, and there might be distribution specific conventions like Debian multiarch and tuples. You'll need to collect info from your distribution's document or other resources online.

yaegashi
  • 12,108
  • 1
  • 36
  • 41
2

Another option is make -v. In my laptop:

$ make -v 
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Then built triple is x86_64-pc-linux-gnu.

mja
  • 1,335
  • 1
  • 14
  • 25
  • 1
    Turns out this answer is wrong. The build triplet is `x86_64-linux-gnu` despite what `make` says. – Joshua May 07 '19 at 02:27
  • @Joshua Please read this: https://wiki.osdev.org/Target_Triplet – mja May 08 '19 at 15:58
  • 1
    Most people need to know the triplet either to know what to pass to `./configure` or to cross-compile something. When cross-compiling, the only name that is relevant is the name the cross tools will take. – Joshua May 08 '19 at 16:06