gcc参数错误导致的makefile错误

今天写一个小makefile文件,出现以下错误:

linux:/mnt/hgfs/vmware-share # make
cc -o my_bin.o my_bin.c
cc -o my_bin my_bin.o
my_bin.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crt1.o:../sysdeps/i386/elf/start.S:65: first defined here
my_bin.o: In function `__data_start':
: multiple definition of `__dso_handle'
/usr/lib/gcc/i586-suse-linux/4.0.2/crtbegin.o:(.data+0x0): first defined here
my_bin.o: In function `_init':
/usr/src/packages/BUILD/glibc-2.3/cc/csu/crti.S:34: multiple definition of `_init'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crti.o:/usr/src/packages/BUILD/glibc-2.3/cc/csu/crti.S:12: first defined here
my_bin.o: In function `_start':
../sysdeps/i386/elf/start.S:65: multiple definition of `_start'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crt1.o:../sysdeps/i386/elf/start.S:65: first defined here
my_bin.o: In function `_fini':
/usr/src/packages/BUILD/glibc-2.3/cc/csu/crti.S:50: multiple definition of `_fini'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crti.o:/usr/src/packages/BUILD/glibc-2.3/cc/csu/crti.S:12: first defined here
my_bin.o: In function `__i686.get_pc_thunk.bx':
/usr/src/packages/BUILD/glibc-2.3/cc/csu/crtn.S:35: multiple definition of `__i686.get_pc_thunk.bx'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crti.o:/usr/src/packages/BUILD/glibc-2.3/cc/csu/crti.S:12: first defined here
my_bin.o:(.got.plt+0x0): multiple definition of `_GLOBAL_OFFSET_TABLE_'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crt1.o:../sysdeps/i386/elf/start.S:65: first defined here
my_bin.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crt1.o:../sysdeps/i386/elf/start.S:71: first defined here
my_bin.o: In function `__data_start':
: multiple definition of `__data_start'
/usr/lib/gcc/i586-suse-linux/4.0.2/../../../crt1.o:../sysdeps/i386/elf/start.S:65: first defined here
collect2: ld returned 1 exit status
make: *** [my_bin] 错误 1

makefile文件:

CC=gcc
INSTDIR=/usr/local/bin/

my_bin : my_bin.o
	$(CC) -o my_bin my_bin.o

my_bin.o : my_bin.c public.h
	$(CC) -o my_bin.o my_bin.c

install : my_bin
	if [ -d $(INSTDIR)]; then \
		cp my_bin $(INSTDIR); \
		chmod a+x $(INSTDIR)/my_bin; \
		echo "install to $(INSTDIR) success"; \
	else \
		echo "sorry, $(INSTDIR) is not exist"; \
	fi    
    
clean:
	rm my_bin my_bin.o

刚开始对这个错误摸不着头脑,后来发现是gcc 参数搞错了。

即红色部分应该为:$(CC) -c my_bin.c



你可能感兴趣的:(gcc参数错误导致的makefile错误)