Objective-C for Windows

210,666

Solution 1

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.

Solution 2

You can use Objective C inside the Windows environment. If you follow these steps, it should be working just fine:

  1. Visit the GNUstep website and download GNUstep MSYS Subsystem (MSYS for GNUstep), GNUstep Core (Libraries for GNUstep), and GNUstep Devel
  2. After downloading these files, install in that order, or you will have problems with configuration
  3. Navigate to C:\GNUstep\GNUstep\System\Library\Headers\Foundation1 and ensure that Foundation.h exists
  4. 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)
  5. 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;
    }
    
  6. 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
    
  7. Finally, from the command prompt, type helloworld to run it

All the best, and have fun with Objective-C!


NOTES:

  1. I used the default install path - adjust your command line accordingly
  2. Ensure the folder path of yours is similar to mine, otherwise you will get an error

Solution 3

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.

Solution 4

Also:

The Cocotron is an open source project which aims to implement a cross-platform Objective-C API similar to that described by Apple Inc.'s Cocoa documentation. This includes the AppKit, Foundation, Objective-C runtime and support APIs such as CoreGraphics and CoreFoundation.

http://www.cocotron.org/

Solution 5

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.

Share:
210,666

Related videos on Youtube

Luther Baker
Author by

Luther Baker

merge delete

Updated on February 22, 2022

Comments

  • Luther Baker
    Luther Baker over 2 years

    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?

  • Dan Udey
    Dan Udey over 15 years
    The Cocotron project is designed to be cross-compiled from XCode, not written on Windows and compiled there.
  • cbrulak
    cbrulak about 15 years
    this isn't a good answer, i'm not even sure why the OP picked this as 'the answer' because CoCotron is for Mac and the OP wants a Windows based solution.
  • Luther Baker
    Luther Baker almost 15 years
    You are correct - I got a little too excited when I read this: "The general goal is to provide complete support on any viable platform, the project is intended to be as portable as possible. However, most of the work at this time is focused on providing support for Microsoft Windows. In particular the NT based versions, 2000 up to Vista."
  • Christopher Lloyd
    Christopher Lloyd over 14 years
    Sorry about not answering your question on the group, to summarize: The APSL sucks and both the runtime and CF are under them.
  • Samuel Smith
    Samuel Smith over 14 years
    What sucks about the APSL? (opensource.apple.com/license/apsl) It's not invasive like the GPL. If you modify covered code then you must make that code available. Covered code would be any modifications that you make to CoreFoundation for example, but would not include you actual program. You also need to clearly mark your modifications. This is a nuisance but worth the trade-off of using Apple's highly tested code isn't it?
  • Christopher Lloyd
    Christopher Lloyd over 14 years
    Long term the hassle of staying in compliance with the license and risk of having the license terminated are not worth the code.
  • Samuel Smith
    Samuel Smith over 14 years
    For the benefit of other readers, what Chris is talking about is summarized here (gnu.org/philosophy/historical-apsl.html). I think the risk of Apple terminating the license is worth using the code. The backlash of them ever doing such a thing will prevent them from doing so except in extremely unlikely cases. I.E. Apple is bought by Oracle and the license is revoked.
  • Christopher Lloyd
    Christopher Lloyd over 14 years
    I don't think you understand how the termination works, it is not something they can do to everyone all at once, the code is licensed under the terms and usable under those terms indefinitely. What can happen is that Apple can single out individuals/companies who they think have violated the license. The FSF already does this with GPL violations, you really think Apple is more friendly to developers than the FSF? If you think the terms are inconsequential and meaningless I'm sure you can convince Apple legal to just take them out.
  • Sean
    Sean about 13 years
    It should be noted that Apple worked with the FSF on changes to the APSL and that the FSF considers the APSL Version 2.0 to be a free software license. gnu.org/philosophy/apsl.html
  • KIRAN K J
    KIRAN K J almost 13 years
    this program could not compile with osc.#import <Foundation/Foundation.h> int main (int argc, const char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@”Testing...\n..1\n...2\n....3”); [pool drain]; return 0; }
  • Martin Berger
    Martin Berger almost 12 years
    This suggested installation didnt work on my PC because i have already installed gcc which i used for nasm. So i just corrected gcc -o helloworld... to c:\gnustep\bin\gcc -o helloworld... and it worked. The alternative would be to modify Environment Variables which i didnt do since i was just sight seeing Objective C. Thanks to teshguru for up to the point answer.
  • Lloyd Sargent
    Lloyd Sargent over 11 years
    From my perspective (as someone who has dealt with BSD, LGPL, MIT and other licenses in a proprietary product) Apple's license is LESS restrictive than the GPL - which frankly is a pain in the butt. If I can get BSD, MIT, or APSL, I would rather work with those than GPL.
  • Lloyd Sargent
    Lloyd Sargent over 11 years
    As far as termination, GPL violations that I have read about were egregious (people stripping out headers, etc.). The only thing in the APSL that I see that you may not like is that it requires you document in the code the changes that you make. Sounds like good programming practice to me. Other than that, I'm puzzled as to what about the APSL you find onerous? It has fewer "gotchas" than the GPL!
  • Cole Tobin
    Cole Tobin over 11 years
    You could always port the Cocoa framworks that are open source. Example being CoreFoundation.
  • uchuugaka
    uchuugaka over 10 years
    Not all of Core Foundation IS open source. A huge amount is closed source.
  • Adam Mendoza
    Adam Mendoza almost 10 years
    I downloaded and run this project using Visual Studio 2013 and I got 30 instances of this error. Error 64 error C2632: 'char' followed by 'bool' is illegal C:\opencflite-code-248-trunk\include\c99\stdbool.h 2‌​0 1 objc
  • Wolfpack'08
    Wolfpack'08 about 9 years
    Consider removing code formatting around the names of things. GNUstep MYSY isn't code, it's just the name of a software. If you want something to stand out, maybe consider emboldening it? And if something connects to a tag, consider using the tag delimiters, but there shouldn't be any reason to put proper names in tag delims.
  • Wolfpack'08
    Wolfpack'08 about 9 years
    X'D I dunno why this guy got a best answer he didn't even try the stuff he's talking about. They should make a new badge for bs answers. No offense @michael. It's an interesting read.
  • Michael Buckley
    Michael Buckley about 9 years
    No offense taken, but for the record, at the time I wrote this answer, I had been struggling for a few weeks to compile Objective-C for Windows, and had tried going both GNUStep and Cocoatron. I eventually was forced to rewrite the project in C++, due to some compiler bugs at the time, and ivars not initialized to 0 on Windows. I did make reference to "I haven't tested those features", but I was talking about the then-new Objective-C 2.0 features, which had only been available on Apple platforms for less than a year when this answer was written, and had just landed in GNUStep.
  • Rahul
    Rahul almost 9 years
    when used yhis c:\gnustep\bin\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 it works fir me
  • Frederik
    Frederik over 2 years
    This project provides a complete GNUstep setup for Windows using MSVC (not MinGW): github.com/gnustep/tools-windows-msvc
  • Frederik
    Frederik over 2 years
    Unfortunately the Windows Bridge for iOS (WinObjC) is no longer being maintained by Microsoft.
  • Frederik
    Frederik over 2 years
    WinObjC is no longer being maintained by Microsoft.
  • Frederik
    Frederik over 2 years
    This project seems to be defunct, as the submodule pointers for gnustep-base and libobjc2 no longer work.