C++: Compiling your C++ app source and header file without using the VS IDE

Just like in an earlier blog where I showed you how to compile C# without using the VS IDE, you can do the same thing with C++, with a few differences.  You might want to take a look at the walkthrough article at: https://msdn.microsoft.com/en-us/library/vstudio/ms235639(v=vs.120).aspx, where it shows you how to build an executable.

To get started

This blog will show you how to compile a C++ file with both a header file and a source file.  The example in paragraph above only for a source file.

Compile a simple program

You will have a printed out a line of text, this is just using the source file, now how do we add a header file?  Again use notepad and enter the following program (scroll to see the code if you want to use the code I created):

On the command line enter this: image

Press enter and you will see the following, if all goes well:

image

Type in the name of the program and hit enter, you will see the following a new command line as the code doesn’t do anything other than call the functions.

image

Sure it’s simple.  That’s what I do.

Code

 

//****** First.h ************************* //Filename: First.h //Make sure to use the same name for the //example to work //This is an example but useless header file #include <iostream>

void Function1(); void Function2(); void Function3(); void Function4(); void Function5(); //***************************************

//************First.cpp***************** #include "first.h"

int main() {     Function1();     std::cout <<"***********************\n"           <<"Finally Main prints out\n"           <<"***********************\n"               << std::endl;     return 0; }

void Function1() {     std::cout <<"***********************\n"                   <<"Function1 prints out.\n"                   <<"***********************\n"               << std::endl;     Function2(); }

void Function2() {     std::cout <<"***********************\n"           <<"Function2 prints out.\n"                   <<"***********************\n"               << std::endl;     Function3(); }

void Function3() {     std::cout <<"***********************\n"           <<"Function3 prints out.\n"                 <<"***********************\n"               << std::endl;     Function4(); }

void Function4() {     std::cout <<"***********************\n"                   <<"Function4 prints out.\n"                   <<"***********************\n"               << std::endl;     Function5(); }

void Function5() {     std::cout <<"***********************\n"           <<"Function5 prints out.\n"           <<"***********************\n"               << std::endl;     }