Trouble with spliting files, (header files, etc)

Hello,

I am trying to learn splitting files and making header files and such,

thus i wrote a small program for the purpose of learning how splitting files work.

Here is the complete program:: which works fine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;


void driver(char *command);

int main()
 {
     char command[100];
    for (cin >> command; !cin.eof(); cin >> command)
    {
       if (cin.eof( ))
        {
            return 0;
        }
        else
        {
            driver(command);
        }
    } return 0;
}

//The driver:

void driver(char *command)
{
     if (!strcmp(command, "new"))
     {
        cout <<"It works!!!";
     }
     else;
}


but when i separate the function into different file i get a compile time error:

Here is my main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
#include "Driver.h"

void driver(char *command);

int main()
 {
     char command[100];
    for (cin >> command; !cin.eof(); cin >> command)
    {
       if (cin.eof( ))
        {
            return 0;
        }
        else
        {
            driver(command);
        }
    } return 0;
}



My Driver.h::

1
2
3
4
5
6
7
8
#ifndef DRIVER_H_INCLUDED
#define DRIVER_H_INCLUDED

void driver(char *command);


#endif // DRIVER_H_INCLUDED


and finally my Driver.cpp::

1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
using namespace std;
#include "Driver.h"
void driver(char *command)
{
     if (!strcmp(command, "new"))
     {
        cout <<"It works!!!";
     }
     else;
}


i have the main.cpp,Driver.h, and the Driver.cpp in the same folder, but when i compile i get this error "....\main.o:main.cpp|| undefined reference to `driver(char*)'| ||=== Build finished: 1 errors, 0 warnings ===|"

i am very confused, it should work fine and it does if i put it all on one file, but when i split it into different files i get an error, according to the error driver is not defined but it is in my header file and my driver.cpp

Your help is very appreciated.
Thank you very much in advance.
Last edited on
You need to make sure that Driver.cpp is compiled and linked to your program.
oh ok, then i'll make a "Make" file
er... you don't have to make a makefile. Just add Driver.cpp as part of your project.
Topic archived. No new replies allowed.