Path: chuka.playstation.co.uk!news From: Toby Sargeant Newsgroups: scee.yaroze.programming.gnu_compiler Subject: Re: undefined reference to Date: Wed, 23 Feb 2000 22:27:26 +1100 Organization: PlayStation Net Yaroze (SCEE) Lines: 65 Message-ID: <38B3C41E.D7EA0B50@fulcrum.com.au> References: <890bpa$6g2@chuka.playstation.co.uk> NNTP-Posting-Host: modem28.csse.monash.edu.au Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.14 i686) X-Accept-Language: en Rikki Prince wrote: > > Can anyone tell me why I keep getting a n 'undefined reference to...' error > when I try to compile my main.c file with three of my own archive/library > files? I've checked that the function is in the archive with nm.exe, and I > can't understand why I can't use the function in my main.c file. If you > think it would be worth posting the files here, I can, but I think it would > be quicker for someone just to tell me what's most likely to be causing the > error (unless of course it's a *really* general error that you get for > everything). nm will also display external references: compiling this: int main(char **argv,int argc) { printf ("hello world\n"); } and then running nm (note, this is on a unix box, so it might look a little different): [toby@localhost toby]$ nm a.out | grep main U __libc_start_main@@GLIBC_2.0 080483c8 T main [toby@localhost toby]$ nm a.out | grep printf U printf@@GLIBC_2.0 if you're sure that your library exports the symbol that you're looking for (which you can check by making sure that there's a T record in the nm dump of the .lib, and a U record with a matching name in the .obj) then the chances are that what's happening is that the ecoff type signatures don't match. A quick test seems to suggest that this doesn't actually happen with ecoff binaries, so it sounds most likely that your library doesn't actually export the function. [toby@localhost toby]$ cat test2.c int test(int x) { return 0; } [toby@localhost toby]$ cat test.c int main(int argc,char **argv) { extern void test(); test(); } [toby@localhost toby]$ psx-gcc -c test2.c [toby@localhost toby]$ psx-ar cr test.lib test2.o [toby@localhost toby]$ psx-gcc test.c test.lib -nostdlib /usr/local/contrib/psxdev/psx/bin/ld: warning: cannot find entry symbol _start; defaulting to 80100000 /tmp/ccBKJ2OL.o: In function `main': test.c(.text+0x14): undefined reference to `__main' test.c(.text+0x14): relocation truncated to fit: JMPADDR __main collect2: ld returned 1 exit status sorry, this probably isn't any help... if things are still going wrong, posting the source might be your best bet. have you tried compiling the exe directly from source, without going via libraries? it might be a pain to set up, but that way you could be sure that it's not some form of symbol munging done by ar that's causing the problem (not, of course, that that's likely). Toby.