Date: Thu, 13 Aug 1998 10:10:18 +0200 (WET) From: Andris Pavenis To: djgpp AT delorie DOT com Subject: Re: please help me to compile an Objective-C program In-Reply-To: <35d25c2c.9025265@news.neosoft.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 13 Aug 1998, Flatulator wrote: > Hi. I'm new to Objective-C and I'm trying to compile this sample > program. I'm using DJGPP v2 to do it. I did everything perfectly as > far as I can tell and I got some "undefined reference" error messages. > The files in question are main.m, Printer.m, and Printer.h. > Here's what I'm typing to compile: > gcc -c main.m (no problem) > gcc -c Printer.m (no problem) > gcc -lobjc main.o Printer.o (Problem occurs here) > > Here are the error messages: > > main.o(.text+0x31):main.m: undefined reference to `objc_get_class' > main.o(.text+0x3c):main.m: undefined reference to `objc_msg_lookup' > main.o(.text+0x54):main.m: undefined reference to `objc_msg_lookup' > main.o(.text+0x77):main.m: undefined reference to `objc_msg_lookup' > main.o(.text+0x9f):main.m: undefined reference to `objc_msg_lookup' > main.o(.text+0xc4):main.m: undefined reference to `objc_msg_lookup' > main.o(.text+0xed):main.m: undefined reference to `__objc_exec_class' > Printer.o(.text+0x20):Printer.m: undefined reference to > `objc_msg_lookup_super' > Printer.o(.text+0x41):Printer.m: undefined reference to > `objc_msg_lookup' > Printer.o(.text+0xb1):Printer.m: undefined reference to > `objc_msg_lookup' > Printer.o(.text+0x105):Printer.m: undefined reference to > `__objc_exec_class' > Printer.o(.text+0x110):Printer.m: undefined reference to > `__objc_class_name_Obje > ct' > > > I would be ever so grateful if some kind soul could help me compile > this program. I feel certain it's a link time error. The contents of > the files in this program follow. Also, I tried compiling this in gcc > in some UNIX and I got the exact same problem. > > Which version of gcc are You using. I'm not specialist in Objective C but compiling and linking for DJGPP with both gcc-2.8.1 and egcs-2.91.93 was successfull (however with warnings). And also program looks working. Output of command: gcc -v main.m Printer.m -lobjc -o test Reading specs from c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/specs gcc version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental) c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/cpp.exe -lang-objc -v -isystem c:/djgpp/bin/include -undef -D__OBJC__ -D__GNUC__=2 -D__GNUC_MINOR__=91 -Dunix -Di386 -DGO32 -DMSDOS -DDJGPP=2 -D__unix__ -D__i386__ -D__GO32__ -D__MSDOS__ -D__DJGPP__=2 -D__unix -D__i386 -D__GO32 -D__MSDOS -D__DJGPP=2 -Asystem(unix) -Asystem(msdos) -Acpu(i386) -Amachine(i386) -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ main.m c:/djgpp/tmp\ccyuqGTe.i GNU CPP version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental) (80386, BSD syntax) #include "..." search starts here: #include <...> search starts here: c:/djgpp/include c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/include c:/djgpp/include End of search list. main.m:1: warning: using `#import' is not recommended The fact that a certain header file need not be processed more than once should be indicated in the header file, not where it is used. The best way to do this is with a conditional of this form: #ifndef _FOO_H_INCLUDED #define _FOO_H_INCLUDED ... ... #endif /* Not _FOO_H_INCLUDED */ Then users can use `#include' any number of times. GNU C automatically avoids processing the file more than once when it is equipped with such a conditional. c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/cc1obj.exe c:/djgpp/tmp\ccyuqGTe.i -quiet -dumpbase main.m -version -lang-objc -o c:/djgpp/tmp\ccnjNul1.s GNU Obj-C version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental) (djgpp) compiled by GNU C version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental). main.m: In function `main': main.m:4: warning: return type of `main' is not `int' c:/djgpp/bin/as.exe -o c:/djgpp/tmp\ccdVc0MZ.o c:/djgpp/tmp\ccnjNul1.s c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/cpp.exe -lang-objc -v -isystem c:/djgpp/bin/include -undef -D__OBJC__ -D__GNUC__=2 -D__GNUC_MINOR__=91 -Dunix -Di386 -DGO32 -DMSDOS -DDJGPP=2 -D__unix__ -D__i386__ -D__GO32__ -D__MSDOS__ -D__DJGPP__=2 -D__unix -D__i386 -D__GO32 -D__MSDOS -D__DJGPP=2 -Asystem(unix) -Asystem(msdos) -Acpu(i386) -Amachine(i386) -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ Printer.m c:/djgpp/tmp\ccyuqGTe.i GNU CPP version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental) (80386, BSD syntax) #include "..." search starts here: #include <...> search starts here: c:/djgpp/include c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/include c:/djgpp/include End of search list. Printer.m:1: warning: using `#import' is not recommended The fact that a certain header file need not be processed more than once should be indicated in the header file, not where it is used. The best way to do this is with a conditional of this form: #ifndef _FOO_H_INCLUDED #define _FOO_H_INCLUDED ... ... #endif /* Not _FOO_H_INCLUDED */ Then users can use `#include' any number of times. GNU C automatically avoids processing the file more than once when it is equipped with such a conditional. c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/cc1obj.exe c:/djgpp/tmp\ccyuqGTe.i -quiet -dumpbase Printer.m -version -lang-objc -o c:/djgpp/tmp\ccnjNul1.s GNU Obj-C version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental) (djgpp) compiled by GNU C version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental). c:/djgpp/bin/as.exe -o c:/djgpp/tmp\ccdpFwY6.o c:/djgpp/tmp\ccnjNul1.s c:/djgpp/lib/gcc-lib/djgpp/egcs-291.53/collect2.exe -o test c:/djgpp/lib/crt0.o -L. -Lc:/djgpp/lib/gcc-lib/djgpp/egcs-291.53 -Lc:/djgpp/bin -Lc:/djgpp/lib c:/djgpp/tmp\ccdVc0MZ.o c:/djgpp/tmp\ccdpFwY6.o -lobjc -lgcc -lc -lgcc -Tdjgpp.djl c:/djgpp/bin/stubify.exe -v test stubify for djgpp V2.X executables, Copyright (C) 1995 DJ Delorie stubify: test -> test.000 -> test.exe