How to compile an objective c program under windows with independant MingW - objective-c

I know how to compile the objective c program using gnustep version of mingw.
But I don't like their shell and I want to use the standard mingw gcc compiler.
I put this gcc bin directory in environment path of course, open command prompt in my helloworld.m directory
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (#"Hello World!");
[pool drain];
return 0;
}
and type
gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
but it doesn't work because it cannot find foundation/foundation.h
How to fix this and if possible avoid hardcoding in hello source code ?

Have a look here at the end of the post the blogger says to write:
gcc `gnustep-config --objc-flags` -o hello2 hello2.m -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base
It seems like you always have to pass through GNUStep

I had the same problem.Modifying command line like below solved my problem.
gcc -I"c:/GNUstep/GNUstep/System/Library/Headers" -L "c:/GNUstep/GNUstep/System/Library/Libraries" -o hello hello.m -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

Related

Link with GNUstep on Ubuntu 14.04, 64 bit

I am attempting to compile a simple application that references GNUstep classes, with GNUstep on my Ubuntu 14.04, 64 bit, machine:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int main(int argc, char **argv)
{
NSString *bestType = [[NSPasteboard generalPasteboard]
availableTypeFromArray: nil];
NSLog(#"best type: %#", bestType);
return 0;
}
Here are my compile and link flags (some of which may be overkill):
CFLAGS=`gnustep-config --objc-flags` -std=gnu99
LDFLAGS=`gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL
Before compilation I ran the script:
/usr/share/GNUstep/Makefiles/GNUstep.sh
And here is the output from 'make -n'
gcc main.m `gnustep-config --objc-flags` -std=gnu99 -L. `gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL -o tester
But when linking, Cocoa classes seem to not be pulled in, and I get an undefined reference error:
/tmp/ccnyXBoH.o:(.data.rel+0x8): undefined reference to `__objc_class_name_NSPasteboard'
If I remove all references to Cocoa classes in main.m, the app compiles without error.
The reason why you can't find the class definition for NSPasteboard is because it's in the gnustep-config --gui-libs options - i.e. the symbol is in the gui library of GNUStep, not in the base library of GNUStep. The solution is to change the LDFLAGS line to:
LDFLAGS=`gnustep-config --gui-libs` -lglut -lGLU -lGL
You shouldn't need to double-specify -lgnustep-base -lobjc -lm - they're part of both --base-libs and --gui-libs.

invoke framework in termimal the window seems to be blocked

now ,I have a framework named "MyFramework.framework" which include a window.nib, and I write a example to invoke it in terminal.
code:
//<MyFramework/myUI.h>
#ifndef Frmwork_myUI_h
#define Frmwork_myUI_h
#ifdef __cplusplus
extern "C"{
#endif
void ShowDialog();
#ifdef __cplusplus
}
#endif
#endif
//test.mm
#include <MyFramework/myUI.h>
#include <Foundation/NSRunLoop.h>
int main(int argc, char *argv[])
{
ShowDialog() ;
while (!isTransmitCompleted)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
return 0;
}
//build test.mm
g++ -c test.mm -o test.o
g++ test.o -o test -lpthread -framework Cocoa -framework AppKit -framework CoreData -framework Foundation -framework MyFramework
//run
$./test
the Dialog can appear, but it seems be blocked ,it has no focus , I can not input anything, I can do nothing ,what is wrong?
now , I got the solution.
In OS X 10.6 ,I write a npapi plugin for Safari, In this plugin I invoke an framework which shows a Modal Window to get password. after close this modal window ,the Safari seems to block.
In my framework , I show this modal window by runModalForWindow function ,when I change to runModalSession , everything works perfectly. I don`t know why but it really works for me .

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

Error With Foundation.h

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.