Having LLVM IR library how to crosscompile it to iOS, Android, Windows and Mac from Ubuntu?

Using the LLVM static compiler (llc), you can compile the LLVM IR into object files for a specific target triple. Though the target triples are not documented very well, the LLVM infrastructure is all open source, so a quick search through the source code will lead you here.

Unfortunately, there is no documentation for a discrete list of possible target triples you can use. However, if you know exactly what system you’re targeting, constructing a triple is fairly easy. Taken from the target triple documentation, you can see :

The triple has the general format <arch><sub>-<vendor>-<sys>-<abi>,
where:

  • arch = x86_64, i386, arm, thumb, mips, etc.
  • sub = for ex. on ARM: v5, v6m, v7a, v7m, etc.
  • vendor = pc, apple, nvidia, ibm, etc.
  • sys = none, linux, win32, darwin, cuda, etc.
  • abi = eabi, gnu, android, macho, elf, etc.

Once you figure out what target triple you’re using, you specify it as a string using the -mtriple flag. Here are some examples:

  • Windows: -mtriple=i686-pc-win32-gnu
  • Linux: -mtriple=i686-pc-linux-gnu
  • IOS: -mtriple=armv7-apple-ios
  • Android: -mtriple=arm-linux-androideabi

Next, you need to specify that you want to compile an object file using the filetype flag:

-filetype=obj

This should be enough if I understand your question correctly.

If you’re expecting to use a single file on all platforms and operating systems, while this is possible, it would take a lot of work and I wouldn’t expect an answer regarding that here on stackoverflow.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)