CC = gcc -O2
objs = foo.o
includedir =
CCFLAGS = -Wall -fno-strength-reduce
all: foo
$(objs): %.o: %.c
$(CC) -I$(includedir) -c $(CCFLAGS) $< -o $@
foo: $(objs)
$(CC) -o $@ $(objs)
the problem is due to _includedir_ having a null string. This Makefile can
produce at least two weird results according to the position of -Idir
option:
1. just like above Makefile, it makes error message:
gcc -O2 -I -c -Wall -fno-strength-reduce foo.c -o foo.o
foo.c: In function `main':
foo.c:5: warning: unused variable `i'
gcc -O2 -o foo foo.o
foo.o(.data+0x0): multiple definition of `__environ'
/usr/lib/crt1.o(.data+0x0): first defined here
foo.o: In function `_init':
foo.o(.init+0x0): multiple definition of `_init'
/usr/lib/crti.o(.init+0x0): first defined here
foo.o: In function `_start':
foo.o(.text+0x0): multiple definition of `_start'
/usr/lib/crt1.o(.text+0x0): first defined here
foo.o: In function `_start':
foo.o(.text+0x0): multiple definition of `___crt_dummy__'
/usr/lib/crt1.o(.text+0x0): first defined here
foo.o: In function `_fini':
foo.o(.fini+0x0): multiple definition of `_fini'
/usr/lib/crti.o(.fini+0x0): first defined here
/usr/lib/libc.so(.dynamic+0x0): multiple definition of `_DYNAMIC'
/usr/lib/libc.so(.got.plt+0x0): multiple definition of `_GLOBAL_OFFSET_TABLE_'
make: *** [foo] Error 1
2. if I put the -Idir option behind the -c option, it seems override the
next option -Wall, no warning!! but no error messages.
gcc -O2 -c -I -Wall -fno-strength-reduce foo.c -o foo.o
gcc -O2 -o foo foo.o
Here is the foo.c:
#include <stdio.h>
int main()
{
int i;
printf("Hello world\n");
return 0;
}
I cant find any exceptions using -Idir option in man pages.
any ideas?
I use gcc-2.7.2, libc-5.3.12
-- Y. Zhu Nagaoka Univ. of Tech. zhu@bousai.nagaokaut.ac.jp