-1

How would I build my c++ code into a dmg file other than a exe file which is what it always builds into. I am trying to make my programs useable by mac users but I cant find answers for this

  • You need far more than just a DMG file writer (a macOS disk-image, for the enquiring minds). You need a cross-compiler to generate mach-o. That's *far* beyond the scope of this site, but probably gave you some fun search terms for your GoogleFu. – WhozCraig Feb 15 '21 at 10:14
  • I think the closest you can get is using something like osxcross running in a docker container and using Visual Studios linux remote development to connect to that. – PeterT Feb 15 '21 at 10:44
  • **Obvious question:** Why does this need to be done through Visual Studio 2019? If your code is portable, then the compiler shouldn't matter -- in which case just compile it on a Mac and produce the proper image. You can use something like [tag:cmake] for this. Even if you don't have a mac, you can probably generate an artifact output from the likes of a Github Action workflow with a macos runner. If your code _isn't_ portable, then you're likely out-of-luck anyway (e.g. Windows headers will not work on Mac) – Human-Compiler Mar 16 '21 at 18:17
  • Yeah, you're right I could do it like that but I was just wondering for vs as it is what I use and I guess I was asking for more of an ease of access thing. –  Mar 21 '21 at 17:07

1 Answers1

2

First off, .dmg on Mac isn't an executable. It's really a packaging tool that includes your executable. If you have a GUI, then what you really need to produce is a .app. If it's just a command line tool, then a binary, just like on Unix. Remember, OSX is very UNIX-like.

I did a Google for "cross compile on windows for mac". Google gave me a bunch of links that go the other way, but if you wade through it, you might find something useful. Depending on what you're building, this is interesting:

https://metricpanda.com/rival-fortress-update-11-cross-compiling-for-three-platforms/

However, if you're trying to write GUIs, you almost certainly need the Mac-specific libraries to link against, and you don't have them.

You MIGHT be able to cross-compile if you switch to Qt as your build environment. I haven't tried that.

If I were going to do this, though, I'd build on Mac. You have to test, anyway, right?

Joseph Larson
  • 8,530
  • 1
  • 19
  • 36