C++ Compilation error - Undefined reference -
i'm having bit of trouble trying compile following simple code in cygwin:
main.cpp:
#include <iostream> #include "point.h" using namespace std; int main() { point a; return 0; }
point.cpp:
#include <iostream> #include "point.h" using namespace std; point::point() { cout << "compile test" << endl; }
point.h:
#ifndef point_h #define point_h class point { public: point(); }; #endif
make file:
cc=g++ cflags=-c -wall ldflags= sources=main.cpp point.cpp objects=$(sources:.cpp=.o) executable=test all: $(sources) $(executable) $(executable): $(objects) $(cc) $(ldflags) $(objects) -o $@ %.o : %.cpp $(cc) $(cflags) -c $< clean: rm -rf *.o core
when try compile main.cpp, i'm getting following error:
main.o:main.cpp:(.text+0x15): undefined reference `point::point()' main.o:main.cpp:(.text+0x15): relocation truncated fit: r_x86_64_pc32 against undefined symbol `point::point()'
and when try compile point.cpp, i'm getting:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.3/../../../../lib/libcygwin.a(libcmain.o): in function `main': /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/lib/libcmain.c:39: undefined reference `winmain' /usr/src/debug/cygwin-2.2.1-1/winsup/cygwin/lib/libcmain.c:39:(.text.startup+0x7f): relocation truncated fit: r_x86_64_pc32 against undefined symbol `winmain'
all files in same directory. should note main class compiles fine if don't create point object. ideas? appreciate help, thanks!
(reposting comments since turned out solve it)
so, assumption build system messed up, , aren't compiling point.cpp
.
you can check if or not looking @ gets printed in console when use make verbose=1
, more info here:
Comments
Post a Comment