Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - makefile error undefined reference to main

Tags:

c

makefile

    dealer: dealer.o readline.o car.o
        gcc -o dealer readline.o car.o

    dealer.o: dealer.c car.h readline.h
        gcc -c dealer.c

    readline.o: readline.c car.h readline.h
        gcc -c readline.c

    car.o: car.c car.h readline.h
        gcc -c car.c

make dealer
gcc -c dealer.c
gcc -c readline.c
gcc -c car.c
gcc -o dealer readline.o car.o
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [dealer] Error 1

I keep getting the error above. My dealer.c does indeed contain 'main'.

Does anybody have an idea on whats going on?

like image 352
jchav Avatar asked Nov 29 '25 20:11

jchav


1 Answers

your link line:

gcc -o dealer readline.o car.o

doesn't contain dealer.o, which explains why main is missing. Should be:

gcc -o dealer dealer.o readline.o car.o

(there's no automatic/guessed relation between the name of the final executable indicated by -o dealer and the object file dealer.o)

like image 77
Jean-François Fabre Avatar answered Dec 01 '25 11:12

Jean-François Fabre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!