5

I cross compiled a program on linux for MacOS and now I want that MacOS binary to convert to DMG file for MacOS.

Is there a way to convert a MacOS binary on Linux (Ubuntu) into DMG file for MacOS?

1

There are several ways that this can be accomplished under Ubuntu and I describe here one technique that I have tested on Ubuntu 18.04 and also tested the resulting dmg file on a colleague's MacOS computer. Out of the several techniques that have been suggested online I believe this one is the better choice!

There are only a few relatively straightforward steps to follow:

  1. Install some applications: First you will need to install hfsprogs which is a port of Apple's Open Source tools for HFS+ filesystems:

    sudo apt-get install hfsprogs
    

    This will provide the necessary tool to work with Apple's HFS+ filesystem.

  2. Create the HFS+ file: Next you will create a 16MB dmg file and format it to HFS+ wih the following two command lines:

    dd if=/dev/zero of=/tmp/my_application.dmg bs=1M count=16 status=progress
    mkfs.hfsplus -v Install /tmp/my_application.dmg
    

    There are a few variables here which you should look at: you can alter the count=16 to reflect the size dmg file that you need and you can alter the volume label, given here as -v Install.

  3. Mount the file, copy your program: Now you can create a mount point, mount your dmg file there, copy your program files to the mounted dmg files and then unmount it all:

    mkdir -pv /mnt/tmp
    sudo mount -o loop /tmp/my_application.dmg /mnt/tmp
    sudo cp -av my_program /mnt/tmp
    sudo umount /mnt/tmp
    

    The variable to alter here is of course the actual name of your application in the cp command which I have given above simply as my_program.

Now your completed dmg file is sitting in /tmp/my_application.dmg ready for deployment and testing on MacOS!

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.