Thursday, September 6, 2012

Common Objective-C error!!


Recently I started learning Objective-C for my new project. Whatever the errors I am getting while compiling, I am sharing here, so that it will be helpfull to others. For Installing Objective-C in windows, see this post. Below are the some of the common errors you may face while compiling Objective-C program in winodws.

$gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries hello.m -o hello -lgnustep-base -lobjc
sh: gcc: command not found 
you may get above error, because system unable to get the gcc path. For this, we need to install devel part in GNUstep installation process (It contains three parts System, Core and devel). The devel binary sets the gcc compilar path, if you forgot to install the devel, you may see above problem.

$ gcc 'gnustep-config --objc-flags' -L /GNUstep/System/Library/Libraries hello.m -o hello -lgnustep-base -lobjc
gcc.exe: error: gnustep-config --objc-flags: No such file or directory
you may get this error, because instead of back-tick(`), you used single quotes(') in the gcc command for gnustep-config parameter.

$ gcc  -L /GNUstep/System/Library/Libraries hello.m -o hello -lgnustep-base -lobjc
hello.m:1:34: fatal error: Foundation/Foundation.h: No such file or directory compilation terminated
you may get the above error, becaus you have not specified the path for the Foundation.h file. we need to specify gnustep-config flag to find the path for the Foundation.h file.

$ gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries hello.m -o hello
C:\Users\CPASUM~1\AppData\Local\Temp\ccifGII6.o:hello.m:(.data+0x0): undefined reference to `__objc_class_name_NSConstantString'
C:\Users\CPASUM~1\AppData\Local\Temp\ccifGII6.o:hello.m:(.data+0x4): undefined reference to `__objc_class_name_NSAutoreleasePool'
AppData\Local\Temp\ccifGII6.o: In function `main':
hello.m:5: undefined reference to `objc_get_class'
hello.m:5: undefined reference to `objc_msg_lookup'
hello.m:5: undefined reference to `objc_msg_lookup'
hello.m:7: undefined reference to `_imp__NSLog'
hello.m:8: undefined reference to `objc_msg_lookup'
ccifGII6.o: In function `_objc_gnu_init':
hello.m:10: undefined reference to `__objc_exec_class'
collect2: ld returned 1 exit status
you may get the above error, because you not specified the library of the objectiveC. This is similar to specifying the math library when you use mathematical functions like sqrt library functions.


$ gcc `gnustep-config --objc-flags` hello.m -o hello -lgnustep-base -lobjc
c:/gnustep/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/ld.exe: cannot find -lgnustep-base
c:/gnustep/bin/../lib/gcc/mingw32/4.6.1/../../../../mingw32/bin/ld.exe: cannot find -lobjc
collect2: ld returned 1 exit status
you may get the above error, becaus you have not specified the gcc library. you need to specify this library becaus , GNUstep runs on MinGW.

These are the some of the common errors. I will update this, whenever I got new errors.

Popular Posts