how to compile a .m

View: New views
8 Messages — Rating Filter:   Alert me  

how to compile a .m

by Jean-Loïc Mauduy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone!

I am new to GNUstep and Objective C and some things seem difficult to understand for me...I hope you can help me. Precision : I'm on Windows.

After installing the thing, I tried a simple hello world, so I put this code in a hello.h :

#import <stdio.h>

int main( int argc, const char *argv[] ) {
    printf( "hello world\n" );
    return 0;
}

and now, how do I compile?

I'm a little bit lost...
Thank you for your help.

_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by Stef Bidi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You'll need a GNUmakefile.  Check this link for a tutorial: http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/

For your simple example I would say:

include $(GNUSTEP_MAKEFILES)/common.make

TOOL_NAME = test
test_OBJC_FILES = hello.m

include $(GNUSTEP_MAKEFILES)/tool.make

Don't forget to source GNUstep.sh before running make (will define GNUSTEP_MAKEFILES).

On Tue, Oct 13, 2009 at 6:30 PM, Jean-Loïc Mauduy <zhorrab@...> wrote:
Hi everyone!

I am new to GNUstep and Objective C and some things seem difficult to understand for me...I hope you can help me. Precision : I'm on Windows.

After installing the thing, I tried a simple hello world, so I put this code in a hello.h :

#import <stdio.h>

int main( int argc, const char *argv[] ) {
    printf( "hello world\n" );
    return 0;
}

and now, how do I compile?

I'm a little bit lost...
Thank you for your help.

_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep



_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by Markus Hitter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Am 14.10.2009 um 01:30 schrieb Jean-Loïc Mauduy:

> I tried a simple hello world, so I put this code
> in a hello.h :

That's hello.m?

> and now, how do I compile?

Use an Obj-C aware compiler, then proceed the same way you do with  
plain C.

You'll soon want to include at least the basic GNUstep libraries. How  
you get this by writing simple makefiles explained Stef Bidi already.


Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/






_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by Jamie Ramone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 13, 2009 at 8:30 PM, Jean-Loïc Mauduy <zhorrab@...> wrote:
> Hi everyone!
>
> I am new to GNUstep and Objective C and some things seem difficult to
> understand for me...I hope you can help me. Precision : I'm on Windows.

Welcome!

> After installing the thing, I tried a simple hello world, so I put this code
> in a hello.h :
>
> #import <stdio.h>
>
> int main( int argc, const char *argv[] ) {
>     printf( "hello world\n" );
>     return 0;
> }
>
> and now, how do I compile?

You need a GNUstep makefile like the one Stef showed in his reply and,
for this code (which is plain C) a compiler. When you get into using
the GNUstep libs, which provide a plethora of objects in Objective C,
you'll have to make sure your compiler handles that language. If it
doesn't you'll need to get one. I recommend using the GNU Compiler
Collection, which includes an Objective C compiler along with the C
compiler and others.

> I'm a little bit lost...
> Thank you for your help.

Don't worry, we all were :-) But the great thing about GNUstep and the
Objective C language is that it's pretty easy to learn.

> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@...
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep
>
>

--
Besos, abrazos, confeti y aplausos.
Jamie Ramone
"El Vikingo"


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A couple of other people have already mentioned GNUstep Make.  For  
short programs, gnustep-config is also an option.  You can compile a  
simple Objective-C program like this:

gcc `gnustep-config --objc-flags --base-libs` hello.m

This will generate an a.out file linked against GNUstep Base  
(Foundation).  Substitute --gui-libs if you want to link AppKit (but,  
generally, if you are linking against AppKit you will want to make a  
bundle and then it's much easier to use GNUstep Make).   For both, you  
will need to source the GNUstep.sh file first, I believe (I'm not 100%  
sure if gnustep-config needs this).

On 14 Oct 2009, at 00:30, Jean-Loïc Mauduy wrote:

> #import <stdio.h>


This is wrong.  A few Objective-C tutorials make this mistake, and  
tell you to just use #import instead of #include in Objective-C  
programs, but this is terrible advice.  #include is a trivial  
preprocessor directive that just inserts the contents of the specified  
file at this point.  #import is a bit more clever, and ensures that  
the file is only ever inserted once.

Objective-C headers are, generally, designed to be used with #import.  
A lot of C (and C++) headers, however, are not.  They will protect  
themselves from multiple inclusion with macros and may be designed to  
work differently if included more than once in a compilation unit.  If  
you get into the habit of using #import with C headers, then you are  
going to end up with something breaking eventually, and you are going  
to be very confused about why.  Only use #import with Objective-C  
headers; stick with #include for C headers.  This also provides a clue  
to people reading your code about what kind of header you are including.

David

-- Sent from my Apple II



_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by Jean-Loïc Mauduy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you everyone for your answers.
The GNUmakefile worked well!
Now I have another .m, that I used in a main.m, described by a .h. How do I include this new information in the makefile?

Thank you for your help!

Jean-Loic


2009/10/14 David Chisnall <theraven@...>
A couple of other people have already mentioned GNUstep Make.  For short programs, gnustep-config is also an option.  You can compile a simple Objective-C program like this:

gcc `gnustep-config --objc-flags --base-libs` hello.m

This will generate an a.out file linked against GNUstep Base (Foundation).  Substitute --gui-libs if you want to link AppKit (but, generally, if you are linking against AppKit you will want to make a bundle and then it's much easier to use GNUstep Make).   For both, you will need to source the GNUstep.sh file first, I believe (I'm not 100% sure if gnustep-config needs this).

On 14 Oct 2009, at 00:30, Jean-Loïc Mauduy wrote:

#import <stdio.h>


This is wrong.  A few Objective-C tutorials make this mistake, and tell you to just use #import instead of #include in Objective-C programs, but this is terrible advice.  #include is a trivial preprocessor directive that just inserts the contents of the specified file at this point.  #import is a bit more clever, and ensures that the file is only ever inserted once.

Objective-C headers are, generally, designed to be used with #import.  A lot of C (and C++) headers, however, are not.  They will protect themselves from multiple inclusion with macros and may be designed to work differently if included more than once in a compilation unit.  If you get into the habit of using #import with C headers, then you are going to end up with something breaking eventually, and you are going to be very confused about why.  Only use #import with Objective-C headers; stick with #include for C headers.  This also provides a clue to people reading your code about what kind of header you are including.

David

-- Sent from my Apple II



_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just add it to the GNUmakefile, so this line

test_OBJC_FILES = hello.m

becomes something like

test_OBJC_FILES = hello.m main.m

You don't need to specify headers in the GNUmakefile unless you are  
building a framework, or some other target where the headers need to  
be installed.

David

On 14 Oct 2009, at 13:28, Jean-Loïc Mauduy wrote:

> Thank you everyone for your answers.
> The GNUmakefile worked well!
> Now I have another .m, that I used in a main.m, described by a .h.  
> How do I include this new information in the makefile?
>
> Thank you for your help!
>
> Jean-Loic
>
>
> 2009/10/14 David Chisnall <theraven@...>
> A couple of other people have already mentioned GNUstep Make.  For  
> short programs, gnustep-config is also an option.  You can compile a  
> simple Objective-C program like this:
>
> gcc `gnustep-config --objc-flags --base-libs` hello.m
>
> This will generate an a.out file linked against GNUstep Base  
> (Foundation).  Substitute --gui-libs if you want to link AppKit  
> (but, generally, if you are linking against AppKit you will want to  
> make a bundle and then it's much easier to use GNUstep Make).   For  
> both, you will need to source the GNUstep.sh file first, I believe  
> (I'm not 100% sure if gnustep-config needs this).
>
> On 14 Oct 2009, at 00:30, Jean-Loïc Mauduy wrote:
>
> #import <stdio.h>
>
>
> This is wrong.  A few Objective-C tutorials make this mistake, and  
> tell you to just use #import instead of #include in Objective-C  
> programs, but this is terrible advice.  #include is a trivial  
> preprocessor directive that just inserts the contents of the  
> specified file at this point.  #import is a bit more clever, and  
> ensures that the file is only ever inserted once.
>
> Objective-C headers are, generally, designed to be used with  
> #import.  A lot of C (and C++) headers, however, are not.  They will  
> protect themselves from multiple inclusion with macros and may be  
> designed to work differently if included more than once in a  
> compilation unit.  If you get into the habit of using #import with C  
> headers, then you are going to end up with something breaking  
> eventually, and you are going to be very confused about why.  Only  
> use #import with Objective-C headers; stick with #include for C  
> headers.  This also provides a clue to people reading your code  
> about what kind of header you are including.
>
> David
>
> -- Sent from my Apple II
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@...
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep


-- Sent from my Apple II



_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Re: how to compile a .m

by Robson Cardoso dos Santos-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I believe this links will help you:

   http://www.gnustep.it/nicola/Tutorials/
   http://www.gnustep.it/nicola/Tutorials/MoreOnMakefiles/index.html

2009/10/14 Jean-Loïc Mauduy <zhorrab@...>:

> Thank you everyone for your answers.
> The GNUmakefile worked well!
> Now I have another .m, that I used in a main.m, described by a .h. How do I
> include this new information in the makefile?
>
> Thank you for your help!
>
> Jean-Loic
>
>
> 2009/10/14 David Chisnall <theraven@...>
>>
>> A couple of other people have already mentioned GNUstep Make.  For short
>> programs, gnustep-config is also an option.  You can compile a simple
>> Objective-C program like this:
>>
>> gcc `gnustep-config --objc-flags --base-libs` hello.m
>>
>> This will generate an a.out file linked against GNUstep Base (Foundation).
>>  Substitute --gui-libs if you want to link AppKit (but, generally, if you
>> are linking against AppKit you will want to make a bundle and then it's much
>> easier to use GNUstep Make).   For both, you will need to source the
>> GNUstep.sh file first, I believe (I'm not 100% sure if gnustep-config needs
>> this).
>>
>> On 14 Oct 2009, at 00:30, Jean-Loïc Mauduy wrote:
>>
>>> #import <stdio.h>
>>
>>
>> This is wrong.  A few Objective-C tutorials make this mistake, and tell
>> you to just use #import instead of #include in Objective-C programs, but
>> this is terrible advice.  #include is a trivial preprocessor directive that
>> just inserts the contents of the specified file at this point.  #import is a
>> bit more clever, and ensures that the file is only ever inserted once.
>>
>> Objective-C headers are, generally, designed to be used with #import.  A
>> lot of C (and C++) headers, however, are not.  They will protect themselves
>> from multiple inclusion with macros and may be designed to work differently
>> if included more than once in a compilation unit.  If you get into the habit
>> of using #import with C headers, then you are going to end up with something
>> breaking eventually, and you are going to be very confused about why.  Only
>> use #import with Objective-C headers; stick with #include for C headers.
>>  This also provides a clue to people reading your code about what kind of
>> header you are including.
>>
>> David
>>
>> -- Sent from my Apple II
>>
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@...
> http://lists.gnu.org/mailman/listinfo/discuss-gnustep
>
>



--
| Robson Cardoso dos Santos
| GPG: 1024D/7E7AFA19 5AA1 BCD8 5770 C3C5 9782 5061 7074 7AAC 7E7A FA19


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@...
http://lists.gnu.org/mailman/listinfo/discuss-gnustep