crosson@cam.nist.gov (Bob_Crosson_x3832) (05/15/91)
I am running Interactive's UNIX 2.2. I am trying to compile a
C program using make and keep getting an error from 'ld'.
Below are a file called 'hello.c', a make file for hello.c, and
the results when make processes the make file. Can anyone tell
me why ld cannot find 'environ'? I have used 'ar' to dump all
of the library element names from the files /lib/lib*.a and
/usr/lib/lib*.a and cannot find environ. I am running the
C-shell. Could that have anything to do with it?
Just 'cc hello.c' produces an a.out that executes correctly.
Thanks in advance for any help. My e-mail address is
crosson@cam.nist.gov
--------------------------------------------------------------
This is the hello.c file:
#include <stdio.h>
main() {
fprintf( stdout, "Hello to you, world\n");
}
--------------------------------------------------------------
# makefile for 'hello.c'
CC = /bin/cc
CFLAGS = -O
LD = /bin/ld
LIBDIR = /lib
LLIBDIR = /usr/lib
LIBS = -Y L,$(LIBDIR) -Y U,$(LLIBDIR)
LDFLAGS = -lc
.c.o :
$(CC) $(CFLAGS) -c $<
hello : hello.o
$(LD) $(LIBS) -o hello hello.o $(LDFLAGS)
--------------------------------------------------------------
Output from running the make file:
/bin/cc -O -c hello.c
/bin/ld -Y L,/lib -Y U,/usr/lib -o hello hello.o -lc
undefined first referenced
symbol in file
environ /lib/libc.a
ld fatal: Symbol referencing errors. No output written to hello
*** Error code 13
cpcahil@virtech.uucp (Conor P. Cahill) (05/15/91)
crosson@cam.nist.gov (Bob_Crosson_x3832) writes: >I am running Interactive's UNIX 2.2. I am trying to compile a >C program using make and keep getting an error from 'ld'. >Below are a file called 'hello.c', a make file for hello.c, and >the results when make processes the make file. Can anyone tell >me why ld cannot find 'environ'? I have used 'ar' to dump all >of the library element names from the files /lib/lib*.a and >/usr/lib/lib*.a and cannot find environ. I am running the Because environ is defined in /lib/crt0.o which is automatically included by CC when it runs LD. That is why it is not recommended that you run LD yourself. Most of the time (like 99.99999% of the time) using CC will do everything you need. Even if you had gotten beyond the environ stuff you probably wouldn't of had a working executable because of no program startup code (which is also in crt0.o. Note that the name of the startup file (crt0.o) changes depending upon your compilation environment (For ex: a posix load will use crtp0.o) -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc. uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170