error linking crt1.o when running make

Hi,

I have run into a problem with a make file on Ubuntu 16.04 although I am not sure this is Linux distro dependent. Anyways I have a clas.h a clas.cpp and a main.cpp witch has the int main(int argc, char* argv[]). g++ -std=c++11 -fpermissive class.cpp main.cpp -o main works like charm and produces the executable and program works very well. Now I wrote an easy makefile (I thought in the beginning it is easy.)

all:main

main: clas.o
g++ -g -std=c++11 -Wall -fpermissive -o main clas.o

clas.o: clas.cpp clas.h
g++ -g -std=c++11 -Wall -fpermissive -c clas.cpp

Now this gives me an error and no executable is produced:
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'

Why do I need to link crt1.o? How do I get rid of this error?

Thanks

Last edited on
You forgot about main.o. You need to add a target for it and use it in the main target like you do with clas.o.
cheers,

that was it!

Z
Hi,

Always compile with a high level of warnings, at least with -Wall -Wextra -pedantic-errors. I wouldn't use -fpermissive - that's cheating :+) There is a strong risk that you are letting things go past the compiler that will only cause problems later on, and that misses the point of having warnings.

Good Luck!!
Thanks for the tip. The -fpermissive is there because I forgot to take it out after my long standing fight with conversion errors from char* to const cahr and so on when reading a binary file or better said trying to figure out the endianness and structure of the binary file. I took out and works like charm! :)
This was a very good shout since I would have forgotten there! thanks,

Z
Topic archived. No new replies allowed.