Objective C for Windows

2019-01-01 04:53发布

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?

13条回答
人间绝色
2楼-- · 2019-01-01 05:05

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.

查看更多
情到深处是孤独
3楼-- · 2019-01-01 05:06

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
查看更多
孤独寂梦人
4楼-- · 2019-01-01 05:08

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.

查看更多
栀子花@的思念
5楼-- · 2019-01-01 05:14

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/

查看更多
大哥的爱人
6楼-- · 2019-01-01 05:17

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.

查看更多
人间绝色
7楼-- · 2019-01-01 05:17

A recent attempt to port Objective C 2.0 to Windows is the Subjective project.

From the Readme:

Subjective is an attempt to bring Objective C 2.0 with ARC support to Windows.

This project is a fork of objc4-532.2, the Objective C runtime that ships with OS X 10.8.5. The port can be cross-compiled on OS X using llvm-clang combined with the MinGW linker.

There are certain limitations many of which are a matter of extra work, while others, such as exceptions and blocks, depend on more serious work in 3rd party projects. The limitations are:

• 32-bit only - 64-bit is underway

• Static linking only - dynamic linking is underway

• No closures/blocks - until libdispatch supports them on Windows

• No exceptions - until clang supports them on Windows

• No old style GC - until someone cares...

• Internals: no vtables, no gdb support, just plain malloc, no preoptimizations - some of these things will be available under the 64-bit build.

• Currently a patched clang compiler is required; the patch adds -fobjc-runtime=subj flag

The project is available on Github, and there is also a thread on the Cocotron Group outlining some of the progress and issues encountered.

查看更多
登录 后发表回答