Q:

Makefile throwing relocation errors

I am trying to write a makefile to compile several files that depend on each other. The file structure is as follows:
- ext2.h
- ext_helper.c
- ext2_cp.c
- ext2_ln.c
- ext2_mkdir.c
- ext2_rm

Each of the source files depend on the ext2.h header file. The last four files are independent of each other but depend on ext2_helper.c for some helper functions.
I've tried to write a makefile for this situation as follows:
ext2_cp :  ext2_helper.o
    gcc -Wall -g -o ext2_cp $^

ext2_mkdir :  ext2_helper.o
    gcc -Wall -g -o ext2_mkdir $^

ext2_ln :  ext2_helper.o
    gcc -Wall -g -o ext2_ln $^

ext2_rm :  ext2_helper.o
    gcc -Wall -g -o ext2_rm $^

%.o : %.c ext2.h
    gcc -Wall -g -c $<

clean : 
    rm *.o ext2_cp ext2_mkdir ext2_ln ext2_rm

However, on running this makefile, I receive several relocation erros as follows:
make
gcc -Wall -g -c ext2_helper.c
gcc -Wall -g -o ext2_cp ext2_helper.o
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 19
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [ext2_cp] Error 1

I've had a look at some other posts with the same problem but do not entirely understand the cause of the error. How would I go about fixing this?

A:

The error message says it all: you're trying to create executables with no main().  It seems that you have forgotten something in your list of dependencies.
Try this:
ext2_cp: ext2_cp.o ext2_helper.o
    gcc -Wall -g -o ext2_cp $^

ext2_mkdir: ext2_mkdir.o ext2_helper.o
    gcc -Wall -g -o ext2_mkdir $^

ext2_ln: ext2_ln.o ext2_helper.o
    gcc -Wall -g -o ext2_ln $^

ext2_rm: ext2_rm.o ext2_helper.o
    gcc -Wall -g -o ext2_rm $^

%.o: %.c ext2.h
    gcc -Wall -g -c $<

clean: 
    rm *.o ext2_cp ext2_mkdir ext2_ln ext2_rm

