Search code examples
iosgccclangcross-compilingjailbreak

Is it possible to compile a X86 program on a jailbroken iOS device?


I have an iPad running iOS 13.5 and it is jailbroken. I installed clang compiler and vim editor on the Cydia store, so I can write code with vim and compile the source code with clang. Both compilation and execution are successful.

Now I have an idea, I know there is a method called cross-compile, so is it possible to compile a C program on iPad that can run in macOS or Windows?


Solution

  • You can certainly compile for macOS. All you need is the SDK with header files and library stubs, which you can either copy from Xcode, or grab from here.
    You can either pass its folder to the compiler with -isysroot, or place/symlink it to /usr/share/SDKs/MacOSX.sdk where the compiler will find it automatically.
    Once you've done that, you can run:

    clang --target=x86_64-apple-darwin -o t t.c
    

    Compiling for Linux or Windows would work in similar fashion with --target=x86_64-linux-gnu and --target=x86_64-windows-msvc respectively, but in addition to a suitable SDK will also require a custom linker. You could presumably build LLVM's lld for iOS and then pass -fuse-ld=ld.lld for Linux or -fuse-ld=lld-link for Windows, but I haven't been able to find this as precompiled binary for iOS.