适用于 Windows 的 Objective-C
在 Windows 平台上编写 Objective-C 的最佳方式是什么?
CYGWIN 和 GCC? 有什么方法可以将其集成到 Visual Studio 中吗?
沿着这些思路 - 对于如何链接和使用 Windows SDK 来完成类似的事情,是否有任何建议。 它是一个不同的野兽,但我知道我可以在 Windows DLL 中编写程序集和链接,使我可以访问这些调用,但我不知道如何在不进行谷歌搜索和获得零碎指示的情况下做到这一点。
有人知道有一个很好的在线或书籍资源可以做或解释这些事情吗?
What would be the best way to write Objective-C on the Windows platform?
Cygwin and gcc? Is there a way I can somehow integrate this into Visual Studio?
Along those lines - are there any suggestions as to how to link in and use the Windows SDK for something like this. Its a different beast but I know I can write assembly and link in the Windows DLLs giving me accessibility to those calls but I don't know how to do this without googling and getting piecemeal directions.
Is anyone aware of a good online or book resource to do or explain these kinds of things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
首先,忘掉GNUStep工具。 既不是 ProjectManager 也不是 ProjectCenter 可以称为IDE。 恕我直言,来自 GNUStep 项目的人似乎还停留在 80 年代末(也就是 NeXTSTEP 首次出现的时候)。
Vim
ctags
自 r771 开始支持 Objective-C (be请务必选择预发行版 5.9 版本并将--langmap=ObjectiveC:.mh
添加到命令行,请参阅 此处),这样您将获得良好的代码完成/标签导航。这是一个简短的操作方法 向 Vim tagbar 插件添加 Objective-C 支持。
Emacs
这同样适用于现代 Emacsen 附带的
etags
,因此您可以从 Emacs 开始Objective C 模式。 YASnippet 将提供有用的模板:如果您愿意比基于标签的基本代码完成更智能的东西,看看这个<一个 href="https://emacs.stackexchange.com/questions/801/how-to-get-intelligent-auto-completion-in-c">问题。
Eclipse
CDT 支持基于
Makefile
的项目:——因此从技术上讲,您可以开箱即用地构建 Objective-C 项目(在 Windows 上,您需要 Cygwin 或 MinGW 工具链)。 唯一的问题是代码编辑器,它会针对它认为的纯 C 代码报告大量错误(可以关闭动态代码检查,但仍然......)。 如果您想要正确的语法突出显示,您可以将 Eclim 添加到您的 Eclipse 中并享受所有功能Eclipse 和 Vim 都有很好的特性(见上文)。
另一个有前途的 Eclipse 插件是 Colorer,但它不支持 Objective -C 到目前为止。 不过,请随意提出功能请求。
SlickEdit
SlickEdit,其中 优秀 IDE 的其他功能,确实 支持 Objective-C。 虽然它学习起来相当复杂(虽然不像 Emacs 那么复杂),但我相信这是您最好的选择,只要您不介意购买它(价格相当实惠)。
此外,它还有一个 Eclipse 插件,可以用作替代方案到独立编辑器。
KDevelop
有传言称存在一个 KDevelop 补丁(15 岁,但谁在乎呢?)。 我个人认为 KDevelop 与 Emacsen 相比,功能并不优越,所以我不会费心去尝试它。
上述内容也适用于 Linux 上的 Objective-C 开发,因为提到的所有工具或多或少都是可移植的。
First of all, forget about GNUStep tools. Neither ProjectManager nor ProjectCenter can be called an IDE. With all due respect, it looks like guys from GNUStep project are stuck in the late 80-s (which is when NeXTSTEP first appeared).
Vim
ctags
support Objective-C since r771 (be sure to pick the pre-release 5.9 version and add--langmap=ObjectiveC:.m.h
to the command line, see here), so you'll have decent code completion/tag navigation.Here's a short howto on adding Objective-C support to Vim tagbar plugin.
Emacs
The same applies to
etags
shipped with modern Emacsen, so you can start with Emacs Objective C Mode. YASnippet will provide useful templates:and if you want something more intelligent than the basic tags-based code completion, take a look at this question.
Eclipse
CDT supports
Makefile
-based projects:-- so technically you can build your Objective-C projects out of the box (on Windows, you'll need the Cygwin or MinGW toolchain). The only problem is the code editor which will report plenty of errors against what it thinks is a pure C code (on-the-fly code checking can be turned off, but still...). If you want proper syntax highlighting, you can add Eclim to your Eclipse and enjoy all the good features of both Eclipse and Vim (see above).
Another promising Eclipse plugin is Colorer, but it doesn't support Objective-C as of yet. Feel free to file a feature request though.
SlickEdit
SlickEdit, among other features of a great IDE, does support Objective-C. While it is fairly complex to learn (not as complex as Emacs though), I believe this is your best option provided you don't mind purchasing it (the price is quite affordable).
Additionally, it has an Eclipse plugin which can be used as an alternative to the stand-alone editor.
KDevelop
Rumor has it there exists a KDevelop patch (15 year old, but who cares?). I personally don't think KDevelop is feature-superior compared to Emacsen, so I wouldn't bother trying it.
The above also applies to Objective-C development on Linux, since all of the tools mentioned are more or less portable.
此处
获取 GNUStep 此处
安装 MINGW
安装GNUStep
然后测试
Get GNUStep here
Get MINGW here
Install MINGW
Install GNUStep
Then Test
如果您熟悉 Visual Studio 环境,
小项目:jGRASP 和 gcc
大型项目:Cocotron
我听说有模拟器,但我只能找到 Apple II 模拟器 http://virtualapple.org/ 。 看起来仅限于游戏。
If you are comfortable with Visual Studio environment,
Small project: jGRASP with gcc
Large project: Cocotron
I heard there are emulators, but I could find only Apple II Emulator http://virtualapple.org/. It looks like limited to games.
截至 2021 年,GNUstep Windows MSVC 工具链允许集成 Objective-C任何 Windows 应用程序中的代码,包括使用 LLVM/Clang 的 Visual Studio 项目。 这包括对自动引用计数 (ARC) 和 Objective-C 2.0 功能(例如块)的支持。
该项目包括来自 GNUstep 的 Foundation、CoreFoundation 和 libdispatch 库。 它目前不包括任何 UI 框架,如 AppKit 或 UIKit,但它可用于编写 Windows 特定的 UI,并使用 Objective-C 编写的跨平台业务逻辑。
As of 2021, the GNUstep Windows MSVC Toolchain allows to integrate Objective-C code in any Windows app, including Visual Studio projects using LLVM/Clang. This includes support for Automatic Reference Counting (ARC) and Objective-C 2.0 features such as blocks.
The project includes the Foundation, CoreFoundation, and libdispatch libraries from GNUstep. It does currently not include any UI framework such as AppKit or UIKit, but it can be used to e.g. write a Windows-specific UI with cross-platform business logic written in Objective-C.
我知道这是一篇非常老的帖子,但我找到了一个最近才可用的解决方案,并且在 Windows 平台上启用了几乎所有 Objective-C 2.0 功能。
随着 gcc 4.6 的出现,Objective-C 编译器中添加了对 Objective-C 2.0 语言功能(块、点语法、综合属性等)的支持(请参阅 发行说明 了解完整详细信息)。 它们的运行时也已更新,几乎与 Apple 自己的 Objective-C 2.0 运行时相同。 简而言之,这意味着(几乎)任何可以在 Mac 上使用 Clang 合法编译的程序也可以使用 gcc 4.6 进行编译,无需修改。
顺便说一句,一个不可用的功能是字典/数组/等文字,因为它们都被硬编码到 Clang 中以使用 Apple 的 NSDictionary、NSArray、NSNumber 等类。
然而,如果您愿意在没有 Apple 广泛框架的情况下生活,您也可以。
正如其他答案中所述,GNUStep 和 Cocotron 提供 Apple 类库的修改版本,或者您可以编写自己的类库(我的首选选项)。
MinGW 是在 Windows 平台上获取 GCC 4.6 的一种方法,可以从 MinGW 网站 下载。 确保安装时包含 C、C++、Objective-C 和 Objective-C++ 的安装。 虽然可选,但我还建议安装 MSYS 环境。
安装后,可以使用以下命令编译 Objective-C 2.0 源
代码: gcc MyFile.m -lobjc -std=c99 -fobjc-exceptions -fconstant-string-class=clsname (等,其他标志,请参阅文档)
MinGW 还支持使用
-mwindows
标志编译本机 GUI Windows 应用程序。 例如:g++ -mwindows MyFile.cpp
我还没有尝试过,但我想如果你在 Objective-C++ 的最高层包装你的 Objective-C 类,你应该能够成功将本机 Windows GUI C++ 和 Objective-C 全部交织在一个 Windows 应用程序中。
I'm aware this is a very old post, but I have found a solution which has only become available more recently AND enables nearly all Objective-C 2.0 features on the Windows platform.
With the advent of gcc 4.6, support for Objective-C 2.0 language features (blocks, dot syntax, synthesised properties, etc) was added to the Objective-C compiler (see the release notes for full details). Their runtime has also been updated to work almost identically to Apple's own Objective-C 2.0 runtime. In short this means that (almost) any program that will legitimately compile with Clang on a Mac will also compile with gcc 4.6 without modification.
As a side-note, one feature that is not available is dictionary/array/etc literals as they are all hard-coded into Clang to use Apple's NSDictionary, NSArray, NSNumber, etc classes.
However, if you are happy to live without Apple's extensive frameworks, you can.
As noted in other answers, GNUStep and the Cocotron provide modified versions of Apple's class libraries, or you can write your own (my preferred option).
MinGW is one way to get GCC 4.6 on the Windows platform, and can be downloaded from The MinGW website. Make sure when you install it you include the installation of C, C++, Objective-C and Objective-C++. While optional, I would also suggest installing the MSYS environment.
Once installed, Objective-C 2.0 source can be compiled with:
gcc MyFile.m -lobjc -std=c99 -fobjc-exceptions -fconstant-string-class=clsname (etc, additional flags, see documentation)
MinGW also includes support for compiling native GUI Windows applications with the
-mwindows
flag. For example:g++ -mwindows MyFile.cpp
I have not attempted it yet, but I imagine if you wrap your Objective-C classes in Objective-C++ at the highest possible layer, you should be able to successfully intertwine native Windows GUI C++ and Objective-C all in the one Windows Application.
最近将 Objective C 2.0 移植到 Windows 的尝试是 Subjective 项目。
来自自述文件:
该项目可在 Github 上找到,还有一个 帖子概述了一些进展和遇到的问题。
A recent attempt to port Objective C 2.0 to Windows is the Subjective project.
From the Readme:
The project is available on Github, and there is also a thread on the Cocotron Group outlining some of the progress and issues encountered.
查看 WinObjC:
https://github.com/Microsoft/WinObjC
Microsoft 的一个官方开源项目,与 Visual Studio + Windows 集成。
Check out WinObjC:
https://github.com/Microsoft/WinObjC
It's an official, open-source project by Microsoft that integrates with Visual Studio + Windows.
如果您只是想尝试一下,这里有一个适用于 .NET (Windows) 的 Objective-C 编译器: qckapp
If you just want to experiment, there's an Objective-C compiler for .NET (Windows) here: qckapp
您可以在这里获得一个可与 Windows 一起使用并与 Visual Studio 2008\2010 良好配合的 Objective C 编译器。
open-c flite
只需下载最新的源代码。 您不需要构建所有 CF-Lite,有一个名为 objc.sln 的解决方案。 您将需要修复一些包含路径,但随后它就会构建得很好。 甚至还包含一个测试项目,因此您可以看到一些 Objective-c .m 文件正在编译并在 Visual Studio 中工作。 一件令人遗憾的事情是它仅适用于 Win32,不适用于 x64。 需要为 x64 编写一些汇编代码才能支持它。
You can get an objective c compiler that will work with Windows and play nice with Visual Studio 2008\2010 here.
open-c flite
Just download the latest source. You don't need to build all of CF-Lite there is a solution called objc.sln. You will need to fix a few of the include paths but then it will build just fine. There is even a test project included so you can see some objective-c .m files being compiled and working in visual studio. One sad thing is it only works with Win32 not x64. There is some assembly code that would need to be written for x64 for it to support that.
我对 Cocotron 项目的感受很复杂。 我很高兴他们发布源代码并共享,但我不认为他们以最简单的方式做事。
示例。
Apple 已将源代码发布到 objective-c 运行时,其中包括属性和垃圾收集。 然而,Cocotron 项目有自己的 Objective-C 运行时实现。 为什么要费力去重复工作呢? 甚至还有一个 Visual Studio 项目文件可用于构建 objc.dll 文件。 或者,如果您真的很懒,您可以从 Windows 上的 Safari 安装中复制 DLL 文件。
他们也懒得利用同样由 Apple 开源的 CoreFoundation。 我发布了 对此提出疑问,但没有收到答案。
我认为当前最好的解决方案是从多个来源(Apple、CocoTron、GnuStep)获取源代码并将其合并到您需要的内容中。 您必须阅读大量源代码,但最终结果是值得的。
I have mixed feelings about the Cocotron project. I'm glad they are releasing source code and sharing but I don't feel that they are doing things the easiest way.
Examples.
Apple has released the source code to the objective-c runtime, which includes properties and garbage collection. The Cocotron project however has their own implementation of the objective-c runtime. Why bother to duplicate the effort? There is even a Visual Studio Project file that can be used to build an objc.dll file. Or if you're really lazy, you can just copy the DLL file from an installation of Safari on Windows.
They also did not bother to leverage CoreFoundation, which is also open sourced by Apple. I posted a question about this but did not receive an answer.
I think the current best solution is to take source code from multiple sources (Apple, CocoTron, GnuStep) and merge it together to what you need. You'll have to read a lot of source but it will be worth the end result.
还:
http://www.cocotron.org/
Also:
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 功能的支持。
我还没有使用 GNUStep 测试这些功能,但是如果您使用足够新的 gcc 版本,您也许可以使用它们。 几年前我还无法将 Objective-C++ 与 GNUStep 一起使用。 然而,GNUStep 几乎可以在任何平台上进行编译。 Cocotron 是一个非常以 Mac 为中心的项目。 虽然可能可以在其他平台上编译它,但它附带 XCode 项目文件,而不是 makefile,因此您只能在 OS X 上开箱即用地编译它的框架。它还附带有关在 XCode 上编译 Windows 应用程序的说明,但不包括任何其他平台。 基本上,为 Cocotron 设置一个 Windows 开发环境是可能的,但这并不像为 GNUStep 设置一个那么容易,而且你需要自己解决,所以如果你正在开发,GNUStep 绝对是你的最佳选择Windows 而不仅仅是 Windows。
就其价值而言,Cocotron 是根据 MIT 许可证获得许可的,而 GNUStep 是根据 LGPL 获得许可的。
Expanding on the two previous answers, if you just want Objective-C but not any of the Cocoa frameworks, then gcc will work on any platform. You can use it through Cygwin or get MinGW. However, if you want the Cocoa frameworks, or at least a reasonable subset of them, then GNUStep and Cocotron are your best bets.
Cocotron implements a lot of stuff that GNUStep does not, such as CoreGraphics and CoreData, though I can't vouch for how complete their implementation is on a specific framework. Their aim is to keep Cocotron up to date with the latest version of OS X so that any viable OS X program can run on Windows. Because GNUStep typically uses the latest version of gcc, they also add in support for Objective-C++ and a lot of the Objective-C 2.0 features.
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.
For what it's worth, Cocotron is licensed under the MIT license, and GNUStep is licensed under the LGPL.
WinObjC? 适用于 iOS 的 Windows Bridge(以前称为“Project Islandwood”)。
Windows Bridge for iOS(也称为 WinObjC)是一个 Microsoft 开源项目,为 Visual Studio/Windows 提供 Objective-C 开发环境。 此外,WinObjC 还提供对 iOS API 兼容性的支持。 虽然最终版本将于今年秋季晚些时候发布(允许该桥利用即将发布的 Visual Studio 2015 更新附带的新工具功能),但
该桥现在已以当前状态向开源社区提供。 从现在到秋天。 iOS 桥作为 MIT 许可下的开源项目。 鉴于该项目的雄心,使 iOS 开发人员能够轻松地在 Windows 上构建和运行应用程序。
Salmaan Ahmed 有一篇关于 iOS 版 Windows Bridge 的深入文章http://blogs.windows.com/buildingapps/2015/08/06/windows-bridge-for-ios-lets-open-this-up/ 讨论编译器、运行时、IDE集成,以及桥梁是什么和不是什么。 最重要的是,iOS 桥的源代码现已发布在 GitHub 上。
iOS 桥同时支持 Windows 8.1 和 Windows 10 个针对 x86 和 x64 处理器架构构建的应用程序,很快我们将添加编译器优化和对 ARM 的支持,从而增加移动支持。
WinObjC? Windows Bridge for iOS (previously known as ‘Project Islandwood’).
Windows Bridge for iOS (also referred to as WinObjC) is a Microsoft open source project that provides an Objective-C development environment for Visual Studio/Windows. In addition, WinObjC provides support for iOS API compatibility. While the final release will happen later this fall (allowing the bridge to take advantage of new tooling capabilities that will ship with the upcoming Visual Studio 2015 Update),
The bridge is available to the open-source community now in its current state. Between now and the fall. The iOS bridge as an open-source project under the MIT license. Given the ambition of the project, making it easy for iOS developers to build and run apps on Windows.
Salmaan Ahmed has an in-depth post on the Windows Bridge for iOS http://blogs.windows.com/buildingapps/2015/08/06/windows-bridge-for-ios-lets-open-this-up/ discussing the compiler, runtime, IDE integration, and what the bridge is and isn’t. Best of all, the source code for the iOS bridge is live on GitHub right now.
The iOS bridge supports both Windows 8.1 and Windows 10 apps built for x86 and x64 processor architectures, and soon we will add compiler optimizations and support for ARM, which adds mobile support.
您可以在Windows环境中使用Objective C。 如果您按照以下步骤操作,它应该可以正常工作:
GNUstep MSYS Subsystem
(GNUstep 的 MSYS)、GNUstep Core
(GNUstep 的库)和GNUstep Devel
C:\GNUstep\GNUstep\System\Library\Headers\Foundation
1 并确保Foundation.h 存在
gcc -v
以检查GNUstep MSYS
是否已正确安装(如果出现文件未找到错误,请确保GNUstep MSYS
已正确安装)GNUstep MSYS
的 >bin 文件夹位于您的PATH
中)使用这个简单的“Hello World”程序来测试 GNUstep 的功能:
返回到命令提示符并
cd
到保存“Hello World”程序的位置,然后然后编译它:2最后,从命令提示符处输入
helloworld
来运行它祝一切顺利,享受 Objective 的乐趣-C!
注意:
You can use Objective C inside the Windows environment. If you follow these steps, it should be working just fine:
GNUstep MSYS Subsystem
(MSYS for GNUstep),GNUstep Core
(Libraries for GNUstep), andGNUstep Devel
C:\GNUstep\GNUstep\System\Library\Headers\Foundation
1 and ensure thatFoundation.h
existsgcc -v
to check thatGNUstep MSYS
is correctly installed (if you get a file not found error, ensure that thebin
folder ofGNUstep MSYS
is in yourPATH
)Use this simple "Hello World" program to test GNUstep's functionality:
Go back to the command prompt and
cd
to where you saved the "Hello World" program and then compile it:2Finally, from the command prompt, type
helloworld
to run itAll the best, and have fun with Objective-C!
NOTES: