Hello everybody.
Help please to write makefile with simple program that is divided into different files.
MyConnection.cpp
MyConnection.hCode:#include "MyConnection.h" #include "MyString.h" // function for working with net int Connection::m_CreateSocket() { int retsocket; if((retsocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { String str; str.m_Error("UDP server - socket() error"); return -1; } return retsocket; }
MyString.cppCode:#ifndef EXPERIMENTAL_SERVER_CONNECTION #define EXPERIMENTAL_SERVER_CONNECTION #include <netinet/in.h> #include <stdio.h> #include <string.h> class Connection { public: Connection(); virtual ~Connection(); protected: int m_fdSocket; sockaddr_in m_serverAddress; int m_CreateSocket(); }; #endif
MyString.hCode:#include "MyString.h" void String::m_Error(char *buffer) { printf(buffer); } // services function for working with strings // print char of string to display void String::m_PrintString(char *buffer) { printf(buffer); }
Main.cppCode:#ifndef EXPERIMENTAL_SERVER_STRING #define EXPERIMENTAL_SERVER_STRING #include <stdio.h> class String { public: String(); virtual ~String(); void m_Error(char *buffer); void m_PrintString(char *buffer); }; #endif
makefileCode:#include <iostream> #include <stdio.h> #include "MyConnection.h" int main(int argc, char *argv[]) { printf("Succ\n"); return 0; }
Code:serverTest: main.cpp MyString.o MyString.h MyConnection.cpp MyConnection.h g++ -o serverTest main.cpp MyString.o MyConnection.cpp MyString.o: MyString.h MyString.cpp g++ -c -g -Wall MyString.cpp
During compilation errors happend
make
g++ -c -g -Wall MyString.cpp
g++ -o serverTest main.cpp MyString.o MyConnection.cpp
/tmp/cc5Aqhjh.o: In function `Connection::m_CreateSocket()':
MyConnection.cpp.text+0x37): undefined reference to `String::String()'
MyConnection.cpp.text+0x5c): undefined reference to `String::~String()'
MyConnection.cpp.text+0x6f): undefined reference to `String::~String()'
collect2: ld returned 1 exit status
make: *** [serverTest] Error 1



LinkBack URL
About LinkBacks
.text+0x37): undefined reference to `String::String()'


