Getting two .cpp files in one .exe

I am needing to get two cpp files to run one exe. I know one of them is supposed to be the "driver". I am using a self made header file and I know one of the cpp files will use the header and run the program, so what would be left for the "driver" file to do and how would I use them to create one exe?
I use dev C++
and in that i add to proj the .cpp file and include the .h file

on the left hand side right click on the project name and select add to project.
then open the file you want to add.
for the .h file type this in the code
#include "file.h"//where file is the file name

note: the file your going to include has to be in the same folder as .dev file


hope this helps!
Header files and source files compile to create an object file. Object files are then linked together to makeup the executable.

For more information on this for Linux platforms, you could Google g++.
Simple way i can try to explain it is.

For 2 .cpp files would be.
1
2
3
4
5
6
7
8
9
/*main.cpp*/
#include <iostream>
#include "headerFile.h"

int main()
{
       myFunction();
       return 0;
}


1
2
3
4
5
6
7
/*headerFile.h*/
#ifndef HEADERFILE_H
#define HEADERFILE_H

void myFunction();

#endif 


1
2
3
4
5
6
7
/*headerFile.cpp*/

#include <iostream>
void myFunction()
{
     std::cout << "Hello World" << std::endl;
}

I'd gather yours is more advanced of program to use. But that would be the basics
Last edited on
also i think this is a small mistake but you also need #include "headerFile.h" in the .cpp file
Topic archived. No new replies allowed.