A simple problem with "include" definition and makefile

This is a discussion on A simple problem with "include" definition and makefile within the C++ Programming forums, part of the General Programming Boards category; Hello everybody. Help please to write makefile with simple program that is divided into different files. MyConnection.cpp Code: #include "MyConnection.h" ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Finland
    Posts
    2

    A simple problem with "include" definition and makefile

    Hello everybody.

    Help please to write makefile with simple program that is divided into different files.

    MyConnection.cpp

    Code:
    #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;
    }
    MyConnection.h

    Code:
    #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.cpp

    Code:
    #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);
    }
    MyString.h

    Code:
    #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
    Main.cpp

    Code:
    #include <iostream>
    #include <stdio.h>
    #include "MyConnection.h"
    
    int main(int argc, char *argv[])
    {
    
       printf("Succ\n");
       return 0;
    }
    makefile


    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

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And where is your definition of the constructor and destructor of String?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Finland
    Posts
    2
    thanks a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. makefile problem
    By v6sa in forum C Programming
    Replies: 3
    Last Post: 05-07-2005, 09:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21