Error With Foundation.h - objective-c

I learning Objective-C in Linux(Ubuntu), but when i tryed to compile my application that needs the Foundation headers i got an error saying that the file cannot be found, but i have installed the GNUstep development package(gnustep-devel). Here is my code:
// Fraction.h
#import <Foundation/NSObject.h>
#interface Fraction: NSObject {
int numerator;
int denominator;
}
- (void) print;
- (void) setNumerator: (int) n;
- (void) setDenominator: (int) d;
- (void) numerator;
- (void) denominator;
#end
And here is the console log:
ubuntu#eeepc:~$ gcc main.m -o frac -lobjc
In file included from main.m:3:
Fraction.h:2:26: error: objc/NSObject.h: No such file or directory
In file included from main.m:3:
Fraction.h:4: error: cannot find interface declaration for ‘NSObject’, superclass of ‘Fraction’
ubuntu#eeepc:~$
What i need to do?

how are you compiling it? For me, I create a GNUMakefile makefile for my application (see here), and then I run source /usr/share/GNUstep/Makefiles/GNUstep.sh and then make.

GNUstep Installation Process For Windows
Visit The URL: http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
Download the exe file gnustep-system-0.19.2-setup.exe
Then Download gnustep-core-0.19.2-setup.exe
Remember one thing if you are downloading gnustep-system of any version you must have to download the same version for gnustep-core.
For example if you have downloaded gnustep-setup-0.22.1-setup.exe then you must have to download gustep-core-0.22.1-setup.exe otherwise your code will not run.
Install first the gnustep-system-0.19.2-setup.exe then install gnustep-core-0.19.2setup.exe. Don’t try to install in vice versa order.
Now you got the gnustep for windows then go to start>all program> GNUstep> shell
Now open the notepad editor and write the following code in notepad
#import
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]
init];
NSLog (#"Anil Kumar Yadav has Run the First Objective C
program!");
[pool drain];
return 0;
}
save it as hello.m in your C:/GNUstep/home/foldername
Remember foldername is the name when you first time start the shell it create the envoirment and make a folder by the name of your computer name in C:/GNUstep/home folder. So don’t be panic.Okay
Go to your shell and type the following command gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -constant-string-class=NSConstantString
This command will create a hello.exe file in your foldername folder.
Again in shell type the command ./hello.exe
Finally you will be able to see the output in the shell.
Conguratulation you wrote your first Objective C program successfully.
Need any clarification write me to : ayadav00009#gmail.com

I've searched at the repository and then i installed the foundation lib, now all is working.
Thanks.

Related

Xcode compilation errors with external library (OSX program)

I have a simple "Hello world" type program in Xcode and I'm trying to use an external library in that, but I'm getting compilation errors. The library is the Magtek edynamo macOS sdk:
https://www.magtek.com/Content/SoftwarePackages/1000004036.zip
(parent page is https://www.magtek.com/support/edynamo?tab=software; download is the macOS SCRA SDK)
This is my code:
#import "MTSCRA.h"
int main (int argc, const char * argv[])
{
MTSCRA* mtSCRALib = [[MTSCRA alloc] init];
return 0;
}
So basically I'm just importing the library and trying to instantiate one of its classes. Xcode doesn't show any inline compile errors anywhere, but when I try to build and run, it results in a variety of undefined symbol errors such as this:
Undefined symbols for architecture x86_64:
"_NSApplicationWillTerminateNotification", referenced from:
-[HIDManager init] in libMTSCRAOSX.a(HIDManager.o)
and warnings such as this:
ld: warning: object file (/path/HelloWorld/libMTSCRAOSX.a(MTSCRA.o)) was built for newer OSX version (10.12) than being linked (10.11)
(If I comment out the MTSCRA* mtSCRALib = [[MTSCRA alloc] init]; line, it runs fine.)
These are the steps I took to include the library in my Xcode project:
I dropped the MTSCRA.h and libMTSCRAOSX.a into my project directory.
From Build phases -> Link binary, I added libMTSCRAOSX.a.
Build Settings -> Library search paths is set to "$(inherited)" and "$(PROJECT_DIR)/HelloWorld"
This is my environment:
Macbook Pro 64-bit
OSX El Capitan 10.11.5
Xcode V8.2.1
Tried all the google solutions; nothing worked. Any help...can anyone else successfully import and use this library?
Solved this. Not sure if these are rookie mistakes, but I had two issues:
1) I also needed to include the library /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.‌​platform/Developer/S‌​DKs/MacOSX.sdk/usr/l‌​ib/libstdc++.6.0.9.t‌​bd
2) I also had to import #import <Cocoa/Cocoa.h>. So:
#import "MTSCRA.h"
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[])
{
MTSCRA* mtSCRALib = [[MTSCRA alloc] init];
return 0;
}

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

objective c libraries on ubuntu

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?

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

Command line tool in Objective-C using Foundation?

is there a simple way to create a command-line tool in Objective C?
I'd rather not use XCode, because XCode has targets and executables, and just complicated stuff.
I'd like to go classic way, just create a Makefile, compile something get an executable, play with it.
--
If this is not possible, is there any way to run the executable I get from regular XCode CL project? It creates a build and again - complicated stuff.
I just want to use my terminal instead of XCode's Console.
Yes. Just write your files as normal Objective-C files and compile with GCC or Clang, linking in the Foundation framework. It's hardly different from a normal C program.
Simple example:
chuck$ cat > main.m
#import <Foundation/Foundation.h>
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *words = [NSArray arrayWithObjects:#"Hello,", #"world!", #"Check", #"this", #"out!", nil];
NSLog(#"%#", [words componentsJoinedByString:#" "]);
[pool release];
return 0;
}
chuck$ cc -framework Foundation -o my-app main.m
chuck$ ./my-app
2010-10-26 22:32:04.652 my-app[5049:903] Hello, world! Check this out!