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

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

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

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


当前回答

扩展前面的两个答案,如果你只想要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许可下授权的。

其他回答

首先,忘记GNUStep工具。ProjectManager和ProjectCenter都不能被称为IDE。恕我直言,GNUStep项目的人似乎还停留在80年代末(那是NeXTSTEP首次出现的时候)。

Vim

ctags从r771开始就支持Objective-C(请务必选择预发布的5.9版本,并在命令行中添加——langmap=ObjectiveC:.m.h,见这里),因此您将拥有良好的代码完成/标记导航。

下面是一个简短的如何将Objective-C支持添加到Vim标记栏插件。

Emacs

这同样适用于现代Emacsen附带的标签,所以您可以从Emacs Objective C Mode开始。YASnippet将提供有用的模板:

如果您想要比基本的基于标记的代码补全更智能的方法,可以看看这个问题。

Eclipse

CDT支持基于makefile的项目:

从技术上讲,你可以开箱即用地构建你的Objective-C项目(在Windows上,你需要Cygwin或MinGW工具链)。唯一的问题是代码编辑器会报告大量错误,而不是它认为的纯C代码(动态代码检查可以关闭,但仍然……)如果希望正确地突出显示语法,可以将Eclim添加到Eclipse中,并享受Eclipse和Vim的所有优秀特性(参见上面)。

另一个很有前途的Eclipse插件是colororer,但它目前还不支持Objective-C。您可以随意提交功能请求。

光滑编辑

SlickEdit,在一个优秀IDE的其他特性中,确实支持Objective-C。虽然它学习起来相当复杂(虽然没有Emacs复杂),但我相信这是您最好的选择,前提是您不介意购买它(价格相当合理)。

此外,它还有一个Eclipse插件,可以作为独立编辑器的替代品。

KDevelop

有传言说存在一个KDevelop补丁(15年了,但谁在乎呢?)我个人并不认为KDevelop在功能上优于Emacsen,所以我不会费心去尝试它。


以上也适用于Linux上的Objective-C开发,因为所有提到的工具或多或少都是可移植的。

你可以在这里得到一个objective - c编译器,它可以在Windows上工作,并且在Visual Studio 2008\2010上运行良好。

open-c争吵

只需下载最新的源代码。你不需要构建所有的CF-Lite有一个解决方案叫做objc.sln。您将需要修复一些包括路径,但它将构建良好。甚至还包含了一个测试项目,这样你就可以看到一些objective-c .m文件正在visual studio中编译和工作。可悲的是,它只适用于Win32而不是x64。需要为x64编写一些汇编代码来支持它。

截至2021年,GNUstep Windows MSVC工具链允许在任何Windows应用程序中集成Objective-C代码,包括使用LLVM/Clang的Visual Studio项目。这包括对自动引用计数(ARC)和Objective-C 2.0特性的支持,比如块。

该项目包括来自GNUstep的Foundation、CoreFoundation和libdispatch库。它目前不包括任何UI框架,如AppKit或UIKit,但它可以用来编写特定于windows的UI,使用Objective-C编写的跨平台业务逻辑。

如果您熟悉Visual Studio环境,

小项目:使用gcc的jGRASP 大型项目:Cocotron

我听说有模拟器,但我只能找到Apple II Emulator http://virtualapple.org/。这似乎仅限于游戏。

你可以在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中玩得开心!


注:

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