objective c libraries on ubuntu - objective-c

I installed GNUStep on Ubuntu 12.10, and some tools for Objective-C development. I then tried to compile the following code.
#import <Foundation/Foundation.h>
int main(int *argc, const char *argv[]) {
NSAutorelease *pool = [[NSAutorelease alloc] init];
NSLog(#"hello world");
[pool drain];
return 0;
}
When I compile it with gcc -o hello hello.m -Wall -lobjc, I get the following error.
Foundation/Foundation.h: No such file or directory; compilation terminated.
I find the Foundation library and other libraries in /usr/include/GNUstep/Foundation. Why am I getting that error message?

Related

#autoreleasepool crashes program with seg fault

I've just installed GNUstep, libobjc2, and llvm on a ubuntu 14.04 box using this script. The installation works for most objective-c2.0 features but not for arc. If I run the following simple program, it crashes as soon as it executes #autoreleasepool with a segmentation fault.
#import <Foundation/Foundation.h>
int main(int argc, char * argv[])
{
#autoreleasepool{
NSLog(#"autoreleasepool works...\n");
}
return 0;
}
I'm compiling with the -fobjc-arc flag. Any suggestions? I've spent two days on this searching the internet. If I use NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init] the program runs.
Mark Allyn

Sublime Text: Is it possible to build a simple - headless - objective-c app?

So, think the classic beginner C programming right of passage: hello world. But written in Objective-C.
For reasons I prefer not to get into, I don't want to use XCode but rather my new love, Sublime Text.
Can it be done?
Paste the following into Sublime and save the file as main.m
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(#"Hello, World!");
[pool drain];
return 0;
}
Then in the terminal navigate to the file with cd and type:
gcc -framework Foundation main.m -o NAME_OF_YOUR_APP
And run the app by typing:
./NAME_OF_YOUR_APP
I did a bit of digging and found this which lets me build and run entirely within Sublime Text which is what I need. Still testing: https://gist.github.com/chendo/4398077

error: cannot find interface declaration for ‘NSAttributedString’ with GNUStep

I have been messing around with GNUStep, and I have a simple main.m, which compiles fine. I wanted to see if objective-c libraries (meant for ios/mac) work with GNUStep, so i downloaded JSONKit and tried to compile that, but I keep getting this error:
mark#Emperor:~/objc-test2$ make
This is gnustep-make 2.6.2. Type 'make print-gnustep-make-help' for help.
Making all for tool Test...
Compiling file JSONKit.m ...
In file included from JSONKit.m:110:0:
JSONKit.h:63:21: warning: "/*" within comment [-Wcomment]
In file included from /usr/include/GNUstep/Foundation/NSAttributedString.h:143:0,
from /usr/include/GNUstep/Foundation/Foundation.h:42,
from JSONKit.h:72,
from JSONKit.m:110:
/usr/include/GNUstep/GNUstepBase/NSAttributedString+GNUstepBase.h:44:1: error: cannot find interface declaration for ‘NSAttributedString’
make[3]: *** [obj/Test.obj/JSONKit.m.o] Error 1
make[2]: *** [internal-tool-all_] Error 2
make[1]: *** [Test.all.tool.variables] Error 2
make: *** [internal-all] Error 2
mark#Emperor:~/objc-test2$
my main.m is this:
mark#Emperor:~/objc-test2$ cat main.m
#import <stdio.h>
#include <Foundation/Foundation.h>
#import "Fraction.h"
#import "JSONKit.h"
int main( int argc, const char *argv[] ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// create a new instance
Fraction *frac = [[Fraction alloc] init];
// set the values
[frac setNumerator: 1];
[frac setDenominator: 3];
// print it
NSLog(# "The fraction is: %#", [frac print]);
// free memory
[frac release];
NSMutableArray *testArr = [[NSMutableArray alloc] initWithCapacity:0];
[testArr addObject:[NSNumber numberWithInt:2]];
[testArr addObject:#"Hey"];
NSLog([testArr JSONString]);
[pool drain];
return 0;
}
mark#Emperor:~/objc-test2$
I've googled around and I have made sure that i have the GNUStep env variables set, and i'm using a make file (taken from examples online)
mark#Emperor:~/objc-test2$ cat GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = Test
Test_OBJC_FILES = main.m Fraction.m JSONKit.m
Test_CPPFLAGS = $(RUNTIME_DEFINE)
# Include in the rules for making Objective-C programs
include $(GNUSTEP_MAKEFILES)/tool.make
mark#Emperor:~/objc-test2$
I really don't get this as /Foundation/NSAttributedString.h clearly contains the interface declaration for NSAttributedString, and NSAttributedString+GNUStepBase.h imports , so any idea on what is going wrong?

A straightforward way of how to compile a program using GNUstep makefiles?

int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(#"Hello World!");
[pool drain];
return 0;
}
This is my program. I have run it on my friends iMac, and there are no problems with the
code. How do I make the makefiles I have been hearing about on GNUstep?
Have you looked at the GNUstep Makefile tutorial? Also the GNUstep make documentation? You should find common.make in the packages you installed already.

compiling Objective-C on Ubuntu using GCC

ok i have this program here:
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (#"Hello world!");
[pool drain];
return 0;
}
the problem is when i compile it with the command
"gcc -framework Foundation prog1.m -o prog1"
i get this:
"gcc: error trying to exec 'cclobj' : execvp: No such file or Directory"
do i need to install any packages??
"
Its not the only way but GNUStep worked for me. For a good writeup on setting it up look here.
Note: Your exact error is listed about halfway down that page. Your missing package seems to be 'gobjc'.
You need to install "gobjc"
Example
gcc -x objective-c -o
check this link Compiling Objective-C using the gcc
http://webcache.googleusercontent.com/search?q=cache:iIgkFc-JoRYJ:https://www.cs.indiana.edu/classes/c304/ObjCompile.html+http://www.it.uc3m.es/mibanez/lao/lab1/tutorial3/ObjCompile.html&cd=1&hl=en&ct=clnk&client=safari