🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #50138

linking errors with <stat.h> commands

#50138
From: Ross Sabolcik
Date: Tue, 16 Nov 1993 22:25
98 lines
3894 bytes
I have the following code fragment:

---------------------------------------------------------------------------

#include <sys/types.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

#define	BUFF_LENGTH	80

main()
{
  char 		*path = NULL;
  struct stat	*buf;
  char 		out_buffer[] = "Hello World";
  FILE 		*write_fd;
  
  /* get the path name for the communication file*/
  if((path = getenv("MITE_FILE")) == NULL){
    printf("MITE_FILE is not defined\n");
    exit(-1);
  }

  /* check if the file has been created */
  if(stat(path, buf) < 0){
	blah.....
  }
blah......
exit(0);
}
---------------------------------------------------------------------------

when I compile this I get the following message:

gcc -O -Wall -o pipe pipe1.c

/tmp/cca011111.o(.text+194): undefined reference to `___stat'
collect2: ld returned 1 exit status
*** Error code 1
make: Warning: Target `pipe' not remade because of errors

-------------------------------------------------------------------------------

now I tried checking out the libc.a library to see if this symbol was defined.
Checking out the directory of the archive gave the following result:

ar -t /usr/local/gnu/lib/libc.a | grep stat
mstats.o
__fstat.o
__lstat.o
__stat.o
fstat.o
lstat.o
stat.o

---------------------------------------------------------------------------
the object file appears to be there, so I try checking out libc.a with
nm to see if the symbol is really there:

nm -a /usr/local/gnu/lib/libc.a | grep ___stat
         U ___stat
00000000 T ___stat
         U ___stat

---------------------------------------------------------------------------

so it looks like the symbol ___stat really is in the libc.a library so
why can't ld find it?  I have similar problems with ___mknod, and
some of the other functions defined in <stat.h>.  (I am rather
inexperienced in ramming around through libraries and am not too
familiar with the innards of the linking process so please be gentle
with me.)  Does ld use the archive directory to find the unresolved
symbols, or does it actually use something like nm to extract the
symbol names and use this?

Could this error be the result of an improperly built library at our
installation?  (I did not build and install gcc).  Or am I not using
the correct versions of the libraries? (ie could I have
GCC_EXEC_PREFIX or LD_LIBRARY or something like that screwed up)

any help/information/etc anyone could provide would be greatly appreciated.

Thanks!!!!!

--------------------------------------------------------------------------------
                                 Ross Sabolcik
                             VXI Software Engineer
                              National Instruments          
                           6504 Bridge Point Parkway
                             Austin, TX 78730-5039                             
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Email: sabolcik@natinst.com                                  Tel: (512) 794-5641
--------------------------------------------------------------------------------
Technical Details
Message-ID: <2cbk1a$46h@eagle.natinst.com>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!natinst.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,8c63d6279dc6a409,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-11-16 17:58:51 PST
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!natinst.com!not-for-mail
From: sabolcik@natinst.com (Ross Sabolcik)
Newsgroups: gnu.gcc.help
Subject: linking errors with <stat.h> commands
Date: 16 Nov 1993 16:25:46 -0600
Organization: National Instruments, Austin, TX
Lines: 98
Message-ID: <2cbk1a$46h@eagle.natinst.com>
NNTP-Posting-Host: eagle.natinst.com