Main Page | Report this Page
Computers Forum Index  »  Computer Languages (Objective-C)  »  can't compile GNUstep objective-C program
Page 1 of 1    

can't compile GNUstep objective-C program

Author Message
Steve
Posted: Thu Sep 16, 2004 6:07 am
Guest
I have successfully installed GNUstep on linux (Redhat 9) and am
trying to compile (using GCC) a simple test program (Fraction.m from
the tutorial at http://www.otierney.net/objective-c.html), however, I
am getting the error "undefined reference to
'__objc_class_name_NSObject'".

I used the compile command:

gcc -o Fraction -I/usr/GNUstep/System/Library/Headers
-L/usr/GNUstep/System/Library/Libraries
Fraction.m
-ldl
-lobjc

If anyone has any clues about this, I would be very grateful.


Cheers,

Steve.
 
Christian Brunschen
Posted: Thu Sep 16, 2004 1:05 pm
Guest
In article <391bb2b1.0409151807.69a21a5@posting.google.com>,
Steve <Rice421@hotmail.com> wrote:
Quote:
I have successfully installed GNUstep on linux (Redhat 9) and am
trying to compile (using GCC) a simple test program (Fraction.m from
the tutorial at http://www.otierney.net/objective-c.html), however, I
am getting the error "undefined reference to
'__objc_class_name_NSObject'".

I used the compile command:

gcc -o Fraction -I/usr/GNUstep/System/Library/Headers
-L/usr/GNUstep/System/Library/Libraries
Fraction.m
-ldl
-lobjc

If anyone has any clues about this, I would be very grateful.

On your command line, you're specifying to link with the 'dl' library
(for dynamic loading I expect), and the 'objc' library, which contains
the GNU Objective-C runtime system. Neither one of those, however,
contains the NSObject class: That's in the GNUStep base library, which
you also will need to specify on the command line. You've already told the
linker where to look for the library
(-L/usr/GNUstep/System/Library/Libraries), now you just need to tell it
which one of those libraries is should link against :)

Quote:
Cheers,

Best wishes,

Quote:
Steve.

// Christian Brunschen
 
Sherm Pendley
Posted: Thu Sep 16, 2004 3:01 pm
Guest
Steve wrote:

Quote:
I have successfully installed GNUstep on linux (Redhat 9) and am
trying to compile (using GCC) a simple test program

Even assuming that you do figure out how to compile a simple one-file
program, you'll soon find that approach doesn't scale very well. It's
just not very practical when your programs consist of dozens, or even
hundreds of source files that each need to be separately compiled and
linked.

What you need to learn is how to create a "make file" - an input file
that's used by the "make" tool to build your program.

A short example can be found here, in section 1.5 of the the GNUStep
Base Programming Manual, entitled "Building Your First Objective-C Program":

<http://tinyurl.com/4ysh2>

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Steve
Posted: Fri Sep 17, 2004 4:23 am
Guest
Thanks for your suggestions. I am still however having some trouble,
i.e. even if I specify the library, gcc will complain that it cannot
find it, even though the path was specified thru -L, i.e.

gcc -o Fraction
-I/usr/GNUstep/System/Library/Headers
-L/usr/GNUstep/System/Library/Libraries
Fraction.m
-lobjc
libgnustep-base.so


The program will compile if I state the full path name of the library,
i.e.

gcc -o Fraction
-I/usr/GNUstep/System/Library/Headers
Fraction.m
-lobjc
/usr/GNUstep/System/Library/Libraries/libgnustep-base.so

however, if I try to run the binary, it complains that it canot find
the shared library (libgnustep-base.so). Adding the library path to
LD_LIBRARY_PATH and /etc/ld.so.conf does not help.


What is going on here ?


Cheers,

Steve.



cb@df.lth.se (Christian Brunschen) wrote in message news:<cibl0i$i89$1@news.lth.se>...
Quote:
In article <391bb2b1.0409151807.69a21a5@posting.google.com>,
Steve <Rice421@hotmail.com> wrote:
I have successfully installed GNUstep on linux (Redhat 9) and am
trying to compile (using GCC) a simple test program (Fraction.m from
the tutorial at http://www.otierney.net/objective-c.html), however, I
am getting the error "undefined reference to
'__objc_class_name_NSObject'".

I used the compile command:

gcc -o Fraction -I/usr/GNUstep/System/Library/Headers
-L/usr/GNUstep/System/Library/Libraries
Fraction.m
-ldl
-lobjc

If anyone has any clues about this, I would be very grateful.

On your command line, you're specifying to link with the 'dl' library
(for dynamic loading I expect), and the 'objc' library, which contains
the GNU Objective-C runtime system. Neither one of those, however,
contains the NSObject class: That's in the GNUStep base library, which
you also will need to specify on the command line. You've already told the
linker where to look for the library
(-L/usr/GNUstep/System/Library/Libraries), now you just need to tell it
which one of those libraries is should link against :)

Cheers,

Best wishes,

Steve.

// Christian Brunschen
 
Steve
Posted: Fri Sep 17, 2004 5:48 am
Guest
I have got it working !!

The trick seems to be to add the library path to /etc/ld.so.conf then
run /sbin/ldconfig to update the cache. Just putting the path into
/etc/ld.so.conf is not enough.

The correct gcc command line is:

gcc -o Fraction
-I/usr/GNUstep/System/Library/Headers
-L/usr/GNUstep/System/Library/Libraries
Fraction.m
-lobjc
-lgnustep-base


Steve.
 
 
Page 1 of 1    
All times are GMT
The time now is Thu Dec 10, 2009 1:27 pm