Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have representations of all my dependencies and my library in LLVM IR forms. How to cross-compile my library into a shared object for iOS, Android, Windows and Mac platforms from Linux ( Ubuntu for example )?

Please provide a single example script that would compile any example library with at least one dependency on to another library of your choice to all 4 platforms ( for example OpenCV or ZeroMQ 4+ ).

like image 500
DuckQueen Avatar asked Jun 07 '17 22:06

DuckQueen


1 Answers

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.

like image 114
ajkhoury Avatar answered Nov 14 '22 02:11

ajkhoury