4

Possible dup of this or this, but even after trying to dig through the answers for a while, I couldn't resolve this.

While trying to compile following makefile,

all:  test

    test:  constants.h Point.h Point.cpp line_t.h line_t.cpp drawing_t.h drawing_t.cpp clipper_t.h clipper_t.cpp main.cpp
        g++ -o test Point.cpp line_t.cpp drawing_t.cpp clipper_t.cpp main.cpp -lglut

I get an error:

g++ -o test Point.cpp line_t.cpp drawing_t.cpp clipper_t.cpp main.cpp -lglut /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In function _start': (.text+0x18): undefined reference tomain' collect2: ld returned 1 exit status make: *** [test] Error 1

I am new at Makefile. I guess, I am missing something too obvious.

Community
  • 1
  • 1
santosh-patil
  • 1,540
  • 1
  • 15
  • 29

1 Answers1

5

Apparently none your files define a function with the signature

int main();

or

int main(int argc, char *argv[]);
pmr
  • 58,701
  • 10
  • 113
  • 156
  • 1
    Found it! I had declared main like.. namespace std{ int main(){ ... } }. Replacing with.. using namespace std; .. done the trick! – santosh-patil Aug 20 '12 at 21:52
  • 3
    @powerpravin Introducing names into the namespace `std` is not allowed. It can lead to really messed up results. – pmr Aug 20 '12 at 22:00