0

I am just learning obj c. I am using GNUStep downloaded from gnustep.org/experience/Windows.html (there are 3 installers - msys system, core, devel) some time back.

Running the below code:

#import <Foundation/Foundation.h>

int main (int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSDictionary *m_Dict =
    [NSDictionary dictionaryWithObjectsAndKeys:
      @"ABC", @"One",
      @"DEF", @"Two",
      @"GHI", @"Three",
      nil ];

    // Print all key-value pairs from the dictionary

    [m_Dict enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
        NSLog(@"%@ => %@", key, obj);
        }];

    [pool drain];
    return 0;
}

is showing an error:

$ gcc -o c c.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Li
``braries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
c.m: In function 'main':
c.m:16:44: error: expected expression before '^' token
c.m:18:1: warning: 'NSDictionary' may not respond to '-enumerateKeysAndObjectsUs
ingBlock:' [enabled by default]
c.m:18:1: warning: (Messages without a matching method signature [enabled by def
ault]
c.m:18:1: warning: will be assumed to return 'id' and accept [enabled by default
]
c.m:18:1: warning: '...' as arguments.) [enabled by default]c

Please suggest what I am doing wrong. searched here on Stackoverflow also but couldn't find much help.

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • 2
    What compiler + runtime are you using? – Steven Fisher Apr 07 '13 at 03:15
  • 1
    You need Clang. Do not use GCC. And make sure you install correct version of runtime and please build the project with GNUstep-make when you have no clue what you are actually doing. – Fred Frith-MacDonald Apr 07 '13 at 05:46
  • I am just learning obj c. I am using GNUStep downloaded from http://www.gnustep.org/experience/Windows.html (there are 3 installers - msys system, core, devel) some time back. – user2253619 Apr 07 '13 at 08:31
  • please suggest that will this work if I use Xcode on mac or i need to use something else? – user2253619 Apr 07 '13 at 08:32
  • I have no idea if clang would work well on Windows. Though it certainly works fine on x86 with some other operating systems like FreeBSD and GNU/Linux. What you were doing was using a new syntax that the obsolete compiler GCC doesn't support. I'd install Ubuntu and also check this page http://wiki.gnustep.org/index.php/ObjC2_FAQ – Fred Frith-MacDonald Apr 07 '13 at 10:16
  • Thanks a lot Fred Frith-MacDonald for throwing light on this...I got it.. – user2253619 Apr 07 '13 at 15:01
  • That's where I was going, too. That's critical information you should have included in your question, or should have added. :) I went ahead and added it for you. – Steven Fisher Apr 07 '13 at 15:37
  • While CLANG is the most up to date Objective-C implementation this other question on SO indicates that CLANG+Obj-C-runtime on Windows is not actively maintained. http://stackoverflow.com/questions/12900596/how-to-compile-objective-c-source-code-with-clang-in-mingw64-x86-via-apple-libob – Warren P Apr 07 '13 at 15:51
  • @Steven Fisher, I think he gave enough information if you actually look at it because the second part already tell us about the compiler and the error isn't of the runtime. – Fred Frith-MacDonald Apr 08 '13 at 13:34
  • Yes, it was enough to make me suspicious at a minimum. But pasting the comment in helped, right? :) – Steven Fisher Apr 08 '13 at 15:15

1 Answers1

0

Your compiler doesn't support blocks. You need to use a modern clang.

Really, if you're learning Objective-C for the purpose of writing code for the Mac or iPhone/iPad, your first step needs to be to purchase a Mac and install Xcode. If you learn using older compilers, you'll be missing out on language features and you'll need to relearn the patterns you use later.

Check Mountain Lion's requirements before purchasing a Mac. You can technically run the latest Xcode on Lion, but I don't think Apple will keep it compatible for long.

Alternately, if you're just trying to learn Objective-C, you'll need to figure out what subset of the language you can use. I suggest this isn't terribly useful outside of iOS/Mac development, though.

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
  • And it seems CLANG+LLVM+ObjC runtime on Windows is not even actively maintained. – Warren P Apr 07 '13 at 15:52
  • Even if someone would trying, it would be so scarcely used as to be unreliable. Objective-C isn't that useful outside of OSX/iOS. – Steven Fisher Apr 07 '13 at 22:49
  • I enjoy using XCode on a Mac, but my attempts to use GnuStep and GCC with Objective-C on Linux have not been any fun, and I imagine that there are even more sharp jagged edges on Windows, where GnuStep and Objective-C are least known and least used. – Warren P Apr 07 '13 at 23:01
  • Or you just use an Ubuntu LiveCD and a thumbdrive. ObjC is useful outside OSX if you actually know how to use it. For instance Apportable uses Cocotron and GNUstep and allow you to port ObjC game from iOS or build your own game on Android OS. There's no subset of the language you cannot use outside Mac. It's subset of the frameworks, not language. – Fred Frith-MacDonald Apr 08 '13 at 09:03
  • It's about goals, really. If your goal is just to learn Objective-C, you can learn it anywhere. If your goal is to learn modern Objective-C, you need a modern Objective-C compiler and a runtime that supports it. If your goal is write apps, you need frameworks that can write apps. If you really know what you're doing, you can port what you need. But I think really identifying the user's goal is the first step in any case. :) – Steven Fisher Apr 08 '13 at 15:18
  • Goal could keep changing by user's newly learned knowledge. So I think the first step is to make sure he knows what he should. Anyway, it's obvious at least to me that user doesn't want to get a Mac else he'd already get a Mac. So a suggestion to get a Mac+just to learn ObjC doesn't make much sense to me. Suggestion that it's not very useful outside of iOS/Mac development also doesn't make sense to me. – Fred Frith-MacDonald Apr 08 '13 at 18:58
  • Thank you Steven and Fred with all the help. Thank you all. – user2253619 Apr 11 '13 at 03:32