Objective-C for Windows - objective-c

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?

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.

You can use Objective C inside the Windows environment. If you follow these steps, it should be working just fine:
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
All the best, and have fun with Objective-C!
NOTES:
I used the default install path - adjust your command line accordingly
Ensure the folder path of yours is similar to mine, otherwise you will get an error

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/

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.

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.

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.

Check out WinObjC:
https://github.com/Microsoft/WinObjC
It's an official, open-source project by Microsoft that integrates with Visual Studio + Windows.

If you just want to experiment, there's an Objective-C compiler for .NET (Windows) here: qckapp

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.

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.

Get GNUStep here
Get MINGW here
Install MINGW
Install GNUStep
Then Test

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.

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.

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.

Related

Light Mono Installation

The mono installation provided at mono-project.com comes packed with several libraries, such as gkt, making the installation quite large (~280MB or so).
Is there any way to provide users with an installation of "just" the mono environment? I am targeting Windows, MacOSX and Linux.
You might be looking for mkbundle which merges your application, the libraries it uses and the Mono runtime into a single executable image. See under "Bundles" in that page.
If you do this though, it may mean that you are distributing LGPL code with all that this implies.
If you are distributing your app for Mac OS X, there is also MonoMacPackager which offers more advanced support for this. I think they have done a bunch of work in the linker to really minimize the amount of Mono that you have to include. It will actually remove unused code from assemblies that you reference.

How to set up a dev. environment for ARM board AT91SAM7-EX256 under x86 Linux?

I am a newbie to embedded developement, as figure shown. I have a small ARM board, AT91SAM7-EX256. I have also a JTAG programmer dongle, too. I am using Linux (Ubuntu x86_32) on my notebook and desktop machine. I'm using CodeSourcery Lite for cross-compiling to ARM-Linux.
Am I right that I can't use this Linux-target cross-compiler to make binary or hex files for the small ARM board (it comes without any operating system)? Should I use the version called ARM EABI instead?
As I see, it's a "generic" ARM compiler. I've read some docs, and there're lot of options to specify the processor type and instruction set (thumb, etc.), there will be no problem with it. But how can I tell the compiler, how should the image (bin/hex) looks like for the specific board (startup, code/data blocks etc.)? (In assemblers, there're the org and load directives for it.)
What software do I need to capture some debug messages from the board on my PC? I don't want to on-board debugging, I just need some detailed run-time signal, more than just blinking leds.
I have an option to use MS-Windows, I can get a dedicated machine for it. Do you recommend it, is it much easier?
Can I use inline assembly somehow in my C code? I dunno anything about that. Can I use C++ or just C?
I have also a question, which don't need to answer: are there really 4096 kind of GNU compilers and cross-compilers (from Linux_x86_32 -> Linux_x86_32, Linux_x86_32 -> Linux_ARM, OSX -> Linux_ARM, PPC_Linux -> OSX) and 16 different GNU compiler sources (as many target platforms/processors exists) around? The signs says "yes", but I can't believe it. Correct me, and show me the GNU compiler which can produce object file for any platform/processor, and the universal linker which can produce executable for any platform.
While Windows is not a "better" platform do this kind of embedded development on, it may be easier to start with since you can get a pre-built environment to work with. For example, Yagarto (which I would recommend).
Setting up an embedded development environment on Linux can require a considerable amount of knowledge, but it's not impossible.
To answer your questions:
Your Linux cross-compiler comes with libraries to build executables for a Linux environment. You have hinted that you want to build a bare-metal executable for this board. While you can do this with your compiler, it will just confuse things. I recommend building a baremetal cross-compiler. Since you're building your own baremetal executable (and thus you are the operating system, the ABI doesn't matter since you're generating all of the code and not interoperating with other previously built code.
There are several versions of the ARM instruction set (and Thumb). You need to generate code for your particular processor. If you generate the code for a newer version of the instruction set, you will likely generate code which generates a reserved instruction exception. Most prebuilt gcc cross-compiler toolchains for ARM are "multilib" and will build for a variety of architectures in both ARM and Thumb.
Not sure exactly what you're looking for here. This is a bare metal platform. You can use the debugger channel to send messages if you're debugging on target, or you'll need to build your own communication channel into the firmware you write (i.e. uart support).
See above.
Yes. See here for details on gcc's extended inline assembly syntax. You can do this in C++ and C. You can also simply link pure assembly files.
There is no universal gcc compiler / linker. You need a uniquely built compiler for each host / target combination you use.
Finally, please take a look at Atmel's documentation. They have a wealth of information on developing for this target as well as a board package with the needed linker directives and example programs. Note of course the package is for Atmel's own eval board, but it will get you started.
http://sam7stuff.blogspot.com/
I use either of the codesourcery lite versions. But I have no use for the gcc library nor a C library, I just need a compiler.
In the gcc 3 days newlib was great, modify two files worth of system support (simple open, close, read, putc type stuff) and you could compile just about anything, but with gcc 4.x you cannot even go back and cross compile gcc 3.x, you have to install an old linux distro in a virtual machine.
To get the gcc library yes you probably want to use the eabi version not the version with linux gnueabi in the file names.
You might also consider llvm (if you dont need a C library, and you will still need binutils), hmm, I wonder if newlib compiles with llvm.
I prefer to avoid getting trapped in sandboxes, learn the tools and how to manipulate the linker, etc to build your binaries.

Using a cocoa command line application in Linux

I'm writing a command line tool in Objective-C (within xCode) that uses the Foundation Framework. I have to use Objective-C because I need to unarchive objects previously archived by NSKeyedArchiver.
My question is, I'm wondering if I can now use this compiled application on my Linux web server.
I'm not sure if there would be a runtime issue or if the executable could be its own standalone program that could actually run on my Linux server.
I'd appreciate any feedback.
You can use The Cocotron to build your app targeted to Linux. It is an actual Cocoa implementation meant to fully interoperate (although it's not 100% complete of course), as opposed to GNUstep which is not meant to work that way. I use this and it is awesome.
No, you cannot run a program that was compiled on and for a Mac on a Linux system. So you will have to compile it for (and on) Linux. Apple's Foundation framework is not available for Linux, but have a look at GNUstep, a free and open Cocoa implementation.
I don't know if GNUstep can read archives that have been archived with Cocoa's NSKeyedArchiver, though.
I have provided a wrap-up on how to compile a command line tool based on the Cocotron Foundation framework on my blog.
This does also include a step by step guide on how to cross compile the Foundation framework for Ubuntu Linux.
Hope this is helpful!

How does one use Obj-C 2.0 with GNUstep?

I'm aware of the existence of libobjc2, and I gather that I'll need to use clang rather than GCC, but I can't find any basic instructions of what's different about the compilation process.
Can anyone give explicit, step-by-step instructions on acquiring, configuring, compiling, and using GNUstep with Objective-C 2.0 in Ubuntu?
Since the GNUStep ObjC2 FAQ has already been referenced, I'll assume you've had a look. I would like to point this out, however:
For more advanced features, currently only supported if you compile with Clang, you will need the GNUstep runtime. This is not currently considered production ready. It should work as a drop-in replacement for the GCC runtime, but some of the advanced features are not well-tested.
The FAQ also calls out the following:
If you are using a recent version of GCC to compile your code then you should have a copy of the Objective-C runtime library that came with your compiler.
If you compile with the -fobjc-nonfragile-abi flag then you will use the new ABI. This is only supported with the GNUstep runtime. This adds:
Property introspection
Introspection on optional protocol methods
Non-fragile instance variables
Forwarding proxy support
So, if you're looking for older functionality via GCC, this tutorial would do the job nicely, as would this one. You've explicitly called out that you're looking to do this with the functionality provided by Clang (via libobjc2), which has its own bed of documentation.
Obtaining a release of Clang and getting set up seems fairly cut and dried. The LLVM Getting Started document is exceptionally robust (full documentation archive here), which should provide insight into getting the backend set up and compiling properly. Some additional insight into the expected build procedure can be found here.
However, compiling an Objective-C application in Clang seems extremely underdocumented and untested at the time of this writing. As features become available and the codebase stabilizes, I imagine more user documentation will go live.
According to the GNUstep Wiki, you need just need to compile your code with -fblocks and -fobjc-nonfragile-abi. Then you just use the language features in your code.

Is it possible to run a compiled program with Xcode on Mac OS X in FreeBSD? (Objective-C/Cocoa)

I have a plan to build a web-site which running CGI made with Cocoa.
My final goal is develop on Mac OS X, and run on FreeBSD.
Is this possible?
As I know, there is a free implementation of some NextStep classes, the GNUStep.
The web-site is almost built with only strings. I read GNUStep documents, classes are enough. DB connection will be made with C interfaces.
Most biggest problem which I'm concerning is linking and binary compatibility. I'm currently configuring FreeBSD on VirtualBox, but I wanna know any possibility informations about this from experts.
This is not a production server. Just a trial. Please feel free to saying anything.
--edit--
I confused Foundation and Cocoa frameworks. What I said was Foundation. Basic classes which just enough to manipulating strings.
It’s entirely possible to cross-develop using Xcode. The Cocotron does this – and provides an implementation of Foundation – but doesn’t currently target FreeBSD. You could probably use it as a template to set up cross-development for BSD targets using GNUstep, but it won’t be easy.
You should be OK with the GNUstep Foundation on FreeBSD 9.0 with Objective-C 2 (clang). See these instructions.
Note: Do not installing under '/' with a FreeBSD default install, because it has little space on the '/' partition. I've used /usr/local/gnustep instead, and made some links as the instructions suggest.
Note II: GNUstep sources from subversion repository didn't compile for me, so I used the latest stable GNUstep sources.
Yes, you can do this, and I am doing it right now successfully using FreeBSD 8.2 and Xcode 4.0, running the Foundation class from The Cocotron. Here is a link: describing exactly what I did to build the cross compiler and set everything up. I also detail in that post, how I attempted to get AppKit (GUI) to work. I failed, it may work in the future, it doesn't fully work yet.
So far it's great. I use a common codebase to write iPhone App (game client) and FreeBSD Game Server; after my server compiles I even have a target rsync the files to my dev box.
One more note, you mention DB, I'm successfully using mysqlclient libraries within my App and my post details how to do that. Since you're building a cross-compiler with The Cocotron you can use any library. Just install the library on FreeBSD first, then create the platform as described.
Sounds like your trying to shoehorn tools onto OS and hardware they were not designed for. There are hacks to get almost anything running on top of anything else but why ask for all the grief?
The entire point of the entire Apple API is that you have integration from hardware to OS to development tools. You supposed to pay more up front in return for greater robustness and lower over all lifecycle cost. (It doesn't always work just like Linux doesn't always save money and Windows doesn't always provide the software choices you need but that is the design goal.) When you break Apple's hardware-OS-Dev trinity you have to start fighting the API and the hardware instead of letting it work for you.
I don't think what you're doing will work and even if it does it will cost a lot of time and in the end time is money. Unless your being forced by external circumstances beyond your control to use this configuration, I would strongly suggest you do whatever it takes to find another way to accomplish what you want.
You won't get binary compatibility. Mac OS X uses the Mach-O object format and FreeBSD uses ELF, like linux. Cocoa won't work on platforms other than Mac OS, but if you stick to POSIX and open-source libraries though, you shouldn't have too much trouble building your CGI (and any dependencies) on your FreeBSD machine.
Also, Cocoa for a website? It's the Mac OS standard library for GUIs, associated datastructures, and various helpers. Apple used to promote something called WebObjects which was similar to Cocoa for the web, but I haven't heard anything about it in ages. I don't think Cocoa will work for a website, unless you just mean write a custom web server that has a graphical front-end in Cocoa.