lmayer@elgin.edu

ConsoleApp

Building a Microsoft Visual C++ Project

After we write a C++ program, we need to be able to compile and run it. In order to do this, many things need to be set up. In Microsoft Visual C++ this is done using something called a "Project". The Project contains all of the C++ files needed to make the executable program (large programs are often made of many individual C++ files). The project also has all of the "options" which tell the compiler how to build the program. The Project must also have room to store temporary files. The temporary files make a project too big to fit on a floppy disk, therefore, the project folder will need to go on the hard disk.

Use the following steps to create a project:

1) Create a folder that will contain the project.

 In class, the best place to create a folder is the My Documents folder.

Open My Documents, right click and select New®Folder. A new folder will appear.

Rename the folder  (I usually use my initials, GNM)

2) Create the project

 Select Start®All Programs®Comp Sci-Programming®Microsoft Visual C++ 6.0

 Select File®New…

  a. Click on Win32 Console Application

  b. Put in a project name (we always use "ConsoleApp", short for Console Application)

  c. Set the location of the project. Click on the box that is to the right of the location field.

   Navigate to the folder that you created in step 1 above.

   If you created the folder in My Documents you will need to go to:

   c:\Documents and Settings\comXXXX\My Documents

  d. Click OK

  e. Click Finish

  f. Click OK

  g. Select the "File View" tab

  h. Expand "ConsoleApp files"

 

YOU NOW HAVE A PROJECT THAT YOU CAN USE TO COMPILE YOUR PROGRAMS

 

To create a new C++ program in the project, do the following:

 Select Project®Add To Project®New…

 Click on C++ Source File

 Specify the name of the file

 Specify the location of the file (this should be on the A: drive)

[If you leave work on the C: drive, there is nothing to stop other students from coping your work]

You can now type in C++ code and run it.

 

To open an existing C++ file into the project:

 Select Project®Add To Project®Files…

 Navigate to your file (which should be on the A: drive)

 You can now run your file.

 

To open an existing project:

Select Start®All Programs®Comp Sci-Programming®Microsoft Visual C++ 6.0

Select File®Open Workspace…

Navigate to your workspace file (it will be a .dsw file) and open it)

 

Things to note:

 

  • 1) If you double click on your C++ file it will open the file in a text editor, HOWEVER, no Project will be open and therefore you will not be able to run your program.
  • 2) A newly created Project will fit on a floppy, HOWEVER, if you start to build programs, the files created in the build process will fill up the floppy. Once the floppy is out of room, the project will crash.
  • 3) You can put an empty Project on a floppy and make a copy whenever you need it.
  • 4) You can reuse a Project. Just delete the C++ file you were working on from the Project and add or create a new file.
  • 5) If you create the wrong kind of Project (for example a Win32 Application instead of a Win32 Console Application), everything will work fine until you go to build, then you will get an error like "error LNK2001: unresolved external symbol WinMain@16")
  • 6) The Project Window that is on the left side of the screen shows the files that are part of the project. When you build the project, those are the files that get built. IT DOES MATTER WHAT FILES YOU MAY BE LOOKIN AT IN THE EDITOR WINDOW!
  • 7) If you do a "Save As…" to create a new file, the new file WILL NOT be added to the project. When you build, you will build the old file, not the one that you are looking at in the editor.
  • 8) If you are running a program and you try to build and run it a second time without stopping the first run you will get the following error "LINK : fatal error LNK1168: cannot open Debug/ConsoleApp.exe for writing"
  • 9) If you somehow get two programs in one project you will get the following error when you try to build the project:
  • Hello2.obj : error LNK2005: _main already defined in Hello.obj
  • Debug/ConsoleApp.exe : fatal error LNK1169: one or more multiply defined symbols found
  • 10) Do not use a "." in any file names. Visual C++ puts the proper suffix on all of the files (for example all of your C++ files will have .cpp at the end) HOWEVER, if you put a period in a file name it will think that you are wanting to over-ride the default suffix. This will prevent things from wo