Strange compiler error: "undefined reference to" main ""

Can someone tell me what that means?

/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/../../../crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status make: *** [program] Error 1 

My make file looks like this:

 program : main.o render.o screenwriter.o g++ -o main.o render.o screenwriter.o -lSDL main.o : main.cpp render.h screenwriter.h g++ -c main.cpp render.h screenwriter.h -lSDL render.o : render.h render.cpp g++ -c render.h render.cpp -lSDL screenwriter.o : screenwriter.h screenwriter.cpp g++ -c screenwriter.h screenwriter.cpp -lSDL clean: rm program main.o render.o screenwriter.o -lSDL 

Thanks.

+4
source share
2 answers

This first rule should be

 program : main.o render.o screenwriter.o g++ -o program main.o render.o screenwriter.o -lSDL 

Assuming you want to link main.o render.o screenwriter.o with program executable

Also, at the compilation stages (-c), the -lDSL bit -lDSL not useful, it is a linker command.

+8
source

Change the second line to:

 g++ -o program main.o render.o screenwriter.o -lSDL ^^^^^^^ 

Otherwise, your output will be main.o, and you will lose it at the input.

Even better than manual service of martyrdom, special macros should be used:

 $(CXX) -o $@ $+ -lSDL 

So, even when you expand your program, you will no longer have to edit this command.

+7
source

Source: https://habr.com/ru/post/1369418/


All Articles