This is the first time I am writing a makefile. This doesn’t work (for example, if I modify ClientSocket.cc it just says “uptodate”. Also throws up lots of dependency errors if I run make myprog). Can you please tell what is wrong in this?
Thank you
myprog: myprog.o Client.o ClientSocket.o Socket.o
g++ -Wall -g Socket.o ClientSocket.o Client.o myprog.o -o myprog
myprog.o: myprog.cc
g++ -Wall -g -c myprog.cc
Client.o: Client.cc Client.h
g++ -Wall -g -c Client.cc
ClientSocket.o: ClientSocket.cc ClientSocket.h
g++ -Wall -g -c ClientSocket.cc
Socket.o: Socket.cc Socket.h
g++ -Wall -g -c Socket.cc
Errors when running make myprog:
cc mprog.o -o myprog
myprog.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
myprog.cc:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
There are many others. Like:
myprog.cc:(.text+0x1a4): undefined reference to `std::cout'
myprog.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Make sure you are using tabs to indent the command lines (it’s impossible to tell whether you are or not from the post, since they would probably be converted to spaces).
EDIT:
From the
ccline and the error messages, it looks like make is using its implicit rule for linking, completely ignoring the one you provided (the first one). I can’t see anything in the makefile that would cause this. A few more things to check:make Client.oand seeing if they work.MakefileI know these suggestions are like tech support asking you whether your computer is plugged in, but everything really looks fine to me. I even copied it, fixed the whitespace, and ran it on my machine. Everything seemed to work.