Date: Tue, 30 Oct 2001 19:25:46 +0100 From: Cliff Sarginson <cliff@raggedclown.net> To: Lucas Bergman <lucas@fivesight.com> Cc: Sam Suh <sam@bigstudios.com>, questions@freebsd.org Subject: Re: Question Message-ID: <20011030192546.B1191@raggedclown.net> In-Reply-To: <15326.58577.644116.716803@apu.five.sight>; from lucas@fivesight.com on Tue, Oct 30, 2001 at 11:35:13AM -0600 References: <3BDE7140.E1DA5ABB@in.ceeyes.com> <3BDEC1EE.672DCC9@bigstudios.com> <15326.53671.687708.44817@apu.five.sight> <20011030175306.A6302@raggedclown.net> <15326.58577.644116.716803@apu.five.sight>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Oct 30, 2001 at 11:35:13AM -0600, Lucas Bergman wrote: > Cliff Sarginson wrote: > > Lucas Bergman wrote: > > > Sam Suh wrote: > > > > venkatn wrote: > > > > > but the compiller is not supporting the getch(), as it shows an > > > > > error say UNDEFINED REFERENCE 'getch'/ > > > > > > > > Hi, 'man 3 getch' reveals to me that you need to include <curses.h>. > > > > Have you included that? > > > > > > You're on the right track, but "undefined reference" is a linker > > > error; no include directive is going to fix it. > > > > Mmm, close, but not quite a cigar. The undefined reference could be > > because of a missing macro definition, which may be included in an > > include file. > > I believe as long as you're using a C compiler that you would probably > get a diagnostic, but not an error, since having functions undeclared > and unprototyped is perfectly legal C, if arguably bad style. Indeed, > the program > No, no, you are missing the point.. Consider the following 'C' program.. #define foo(a,b) printf("%s %s\n",a,b) main() { foo("hello","sailor"); } No problems. Now coment out the macro definition. /* #define foo(a,b) printf("%s %s\n",a,b) */ main() { foo("hello","sailor"); } This will compile If you do a "cc -c foo.c" you will get a foo.o without complaint. If you do a "cc foo.c" the loader, ld, will bitch about an undefined reference. The point is that the complaint from "ld" is caused by an undefined reference, without a prototype the compiler could not care less, the assumption being that the reference will be fixed up in ld with whatever libraries or other object files linked in. However "foo" does not exist in any library in this example, so ld complains. If however "foo" is defined as a macro then the "C" preprocessor simply expands the macro and all the "C" compiler proper sees is inline "C". So an undefined reference can have two potential causes, a library call without linking to that library, or a missing macro definition from an include file. Try it out if you do not believe me. -- Regards Cliff To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011030192546.B1191>