how to compile objective-c source code with clang in mingw64-x86 via apple libobjc.dll?

吃可爱长大的小学妹 提交于 2019-12-06 04:42:16

Well, first of all this is in violation of the iTunes EULA, so whether commercial or not you're not supposed to do it.

Second problem is that -fnext-runtime in clang/gcc only functions on Darwin, it is missing assorted bits and pieces for Windows and other operating systems. I'd (educated) guess and assume -fgnu-runtime is useless for linking against Apple's own frameworks.

As you can see -fnext-runtime is emitting Darwin specific assembler command, e.g. .lazy_reference, on Windows, not a great start.

This has been the situation with -fnext-runtime in gcc and now clang for quite a long time, no one maintains -fnext-runtime in the mainlines for non-Darwin systems.

My rough understanding is that Apple actually does not use clang directly on Windows, they rewrite the Objective-C into C and use Visual Studio to compile for Windows.

You can either start doing some serious hacking on clang, or don't bother.

I tried to do exactly the same as you have recently, and I found similar results. The core (technical, not legal) issue is that -fnext-runtime isn't supported on Windows and probably won't ever be supported. I will get to -fgnu-runtime in a moment.

No matter how basic an Objective-C program you write on Windows you will always end up with unresolved references. Looking inside the .dll files you will find that they simply do not contain some of the core methods required to link an Objective-C program compiled with Clang on Windows. (If memory serves I was able to compile a program that had only 2 unresolved references as a minimum).

So on the basis that -fnext-runtime is not supported, you can try -fgnu-runtime with GCC. Of course, you lose compatibility with all Apple's libraries, but you do get working Objective-C programs on Windows. GCC recently upgraded their Objective-C runtime to work almost identically to Apple's Objective-C runtime so compatibility is now much less of an issue.

Again, you don't get Apple's libraries, you'd have to write them yourself (any takers?) but the runtime works in the same way. It takes a bit of working to make your own NSObject (looking at Apple's implementation helps though) and Constant String @"..." object but once you have them, you can build up your own Windows-compatible Objective-C framework. From experience I can tell you that it is definitely possible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!