Compiling With Visual C++
Building a Multiple-File Project -- Console Program
Creating a New Project
-
Open Visual C++ and select New from the File menu.
-
Under the Projects tab, select "Win32 Console Application"
-
This will build a console program only. This is not for GUI projects
-
Type a name for the project in the "Project name" box, select a directory
to save the project in ("Location" box), and click "OK". (Make sure
the "Create New Workspace" button is checked).
-
In the next dialog box, titled "Win32 Console Application - Step 1 of 1",
select "An empty project" and click "Finish", then click "OK" on the next
pop-up box.
Creating a New Code File in the Project
-
Once the project is open, to create a new code file as part of the open
project, select New from the File menu.
-
Under the File tab, select either the "C/C++ Header File" (to create
a new header file) or "C++ Source File" (to create a .cpp file).
-
Make sure the "Add To Project" box is checked, and the project name shows
up in the box just below.
-
Type a filename in the "Filename" box, and select a directory to store
it in, in the "Location" box.
-
Click "OK"
-
A blank page will come up in the text editor. Type your code for
the given file here.
Adding an Existing Code File to the Project
-
In the open project, select Add To Project --> Files from the Project
menu.
-
Use the dialog box that comes up to locate and select the file(s) to add
to the project, then click OK.
-
You can select more than one file by holding down the "Ctrl" key and clicking
on each file you want to add to the project.
Viewing the list of files that currently make up the project
-
In the window on the left of the screen, there should be two tabs at the
bottom: "Class View" and "File View". Click on the "File View"
tab.
-
Click the + symbols in the window to expand the information about the project.
-
Under the project heading, there should be folders called "Source Files"
and "Header Files". All of your .cpp files should show up in the
first of these. The header files (the .h files) should show up in
the latter.
-
Make sure that all files needed to make up an executable have been
added to the project (and only once each) before trying to build the project.
Building the Project
-
In the Build menu, there should now be a selection starting with
"Build..." and ending with the name of your executable. Select this
option to build your project.
-
Alternately, in the "File View" window, you can right-click on the project
name and select "Build".
-
Assuming that the build finishes (i.e. no compile or link errors), you
can run your executable with the Execute... command now appearing
in the Build menu.