在Windows平台上编写Objective-C的最佳方法是什么?

Cygwin和gcc?有没有办法我可以以某种方式将它集成到Visual Studio?

沿着这条线-关于如何链接和使用Windows SDK来做这样的事情有什么建议吗?这是一个不同的野兽,但我知道我可以在Windows dll中编写汇编和链接,让我可以访问这些调用,但我不知道如何做到这一点,除非谷歌和得到零碎的方向。

有人知道有好的网络或书籍资源来做或解释这些事情吗?


当前回答

如果你只是想尝试一下,这里有一个用于。net (Windows)的Objective-C编译器:qckapp

其他回答

你可以在Windows环境中使用Objective C。如果你按照以下步骤操作,它应该可以正常工作:

Visit the GNUstep website and download GNUstep MSYS Subsystem (MSYS for GNUstep), GNUstep Core (Libraries for GNUstep), and GNUstep Devel After downloading these files, install in that order, or you will have problems with configuration Navigate to C:\GNUstep\GNUstep\System\Library\Headers\Foundation1 and ensure that Foundation.h exists Open up a command prompt and run gcc -v to check that GNUstep MSYS is correctly installed (if you get a file not found error, ensure that the bin folder of GNUstep MSYS is in your PATH) Use this simple "Hello World" program to test GNUstep's functionality: #include <Foundation/Foundation.h> int main(void) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello World!."); [pool drain]; return; } Go back to the command prompt and cd to where you saved the "Hello World" program and then compile it:2 gcc -o helloworld.exe <HELLOWORLD>.m -I /GNUstep/GNUstep/System/Library/Headers -L /GNUstep/GNUstep/System/Library/Libraries -std=c99 -lobjc -lgnustep-base -fconstant-string-class=NSConstantString Finally, from the command prompt, type helloworld to run it

祝一切顺利,并在Objective-C中玩得开心!


注:

我使用默认的安装路径-相应地调整您的命令行 确保您的文件夹路径与我的文件夹路径相似,否则将报错

另外:

Cocotron是一个开源项目,旨在实现一个类似于苹果公司Cocoa文档所描述的跨平台Objective-C API。这包括AppKit, Foundation, Objective-C运行时和支持api,如CoreGraphics和CoreFoundation。

http://www.cocotron.org/

扩展前面的两个答案,如果你只想要Objective-C而不是任何Cocoa框架,那么gcc可以在任何平台上工作。你可以通过Cygwin或者MinGW使用它。但是,如果您想要Cocoa框架,或者至少是其中一个合理的子集,那么GNUStep和Cocotron是您最好的选择。

Cocotron实现了很多GNUStep没有实现的东西,比如CoreGraphics和CoreData,尽管我不能保证它们在特定框架上的实现有多完整。他们的目标是让Cocotron与OS X的最新版本保持同步,这样任何可行的OS X程序都可以在Windows上运行。因为GNUStep通常使用最新版本的gcc,他们还添加了对objective - c++和许多Objective-C 2.0特性的支持。

I haven't tested those features with GNUStep, but if you use a sufficiently new version of gcc, you might be able to use them. I was not able to use Objective-C++ with GNUStep a few years ago. However, GNUStep does compile from just about any platform. Cocotron is a very mac-centric project. Although it is probably possible to compile it on other platforms, it comes XCode project files, not makefiles, so you can only compile its frameworks out of the box on OS X. It also comes with instructions on compiling Windows apps on XCode, but not any other platform. Basically, it's probably possible to set up a Windows development environment for Cocotron, but it's not as easy as setting one up for GNUStep, and you'll be on your own, so GNUStep is definitely the way to go if you're developing on Windows as opposed to just for Windows.

值得注意的是,Cocotron是在MIT许可下授权的,GNUStep是在LGPL许可下授权的。

查看WinObjC:

https://github.com/Microsoft/WinObjC

它是微软的官方开源项目,集成了Visual Studio + Windows。

我对Cocotron项目百感交集。我很高兴他们发布源代码和共享,但我不觉得他们做事情的方式是最简单的。

的例子。 苹果已经发布了objective-c运行时的源代码,其中包括属性和垃圾收集。然而,Cocotron项目有自己的objective-c运行时实现。为什么要麻烦地复制这种努力呢?甚至有一个Visual Studio项目文件可以用来构建objc.dll文件。或者,如果您真的很懒,可以从Windows上的Safari安装中复制DLL文件。

他们也懒得利用CoreFoundation(苹果也是开源的)。我发布了一个关于这个问题的问题,但没有收到答案。

我认为目前最好的解决方案是从多个来源(Apple, CocoTron, GnuStep)获取源代码,并将其合并到一起以满足您的需要。你需要阅读大量的资料,但最终的结果是值得的。