1.10.2. Programming With An IDE

Time: 00:03:17 | Download: Large, Large (CC) Small | Streaming, Streaming (CC) | Slides (PDF)

Programmers can write and compile C++ programs using many tools. For example, I used the vi text editor for a dozen years as a professional software engineer; today, I continue using an updated version of that editor with a command-line compiler. But programmers now have more modern tools available. The most frequently used desktop operating systems support powerful, integrated development environments (IDEs). An IDE minimally includes an editor and a compiler, but most also include a debugger, a profiler, a dynamic syntax checker, searchable documentation, and a host of other utilities. While each IDE is unique, there are some common features.

An IDE manages many programs, each consisting of one or more files. To ensure that each file becomes a part of the correct program, the IDE organizes the files into solutions and projects. Before using an IDE to write and compile a program, we must understand how an IDE uses these containers.

Solutions and projects are containers forming a simple IDE database to organize and build programs. Solutions are the outer container that contains one or more projects. Projects are the inner container that contains individual program files. Our first programs will consist of a single source code file whose name ends with a .cpp extension. Later, our programs will consist of multiple files, with both source code (ending with .cpp) and header files (ending with .h extensions.

An abstract representation of solutions and projects as a Venn diagram. Solutions and projects are containers: each project contains at least one file, and each solution contains at least one project.
Solutions and projects viewed as a Venn diagram. The figure illustrates a solution containing three projects. Each project may contain multiple files, some ending with a .cpp extension and others with a .h extension.

Solutions and projects are logical structures. They describe the files the compiler system must compile and link to form an executable program. So, the IDE must have a way to physically organize the files. Separating the logical and physical organizations allows programmers to share files across programs. IDEs implement solutions and projects as folders and sub-folders (or directories and sub-directories). Programmers give the solution and project folders the same or different names. Once programmers create the solution and project folders, they create and write the source code files. The compiler treats all the code in a project as a single program: there must be exactly one file containing exactly one function named main.

Solution and project folders arranged as an inverted filesystem tree with the project folder beneath the solution folder.
A Visual Studio Example. IDEs implement solutions and projects as directories or folders. Solutions are the top-level directories, and the projects are sub-directories of the solutions. The illustration does not show any file structure above the solution directory. Programmers may specify the location of the solution directories when they create them. The names that programmers give the solutions and projects replace "Solution" and "Project," as seen in the figure. Programmers must place all program files in a project directory. The project and solution folders may also contain some IDE-specific files and folders. The two "Debug" folders illustrated here reflect Microsoft's Visual Studio IDE; other IDEs may not have them.
Project ≡ Program

A project represents a single program and so must have exactly one file that has a function named main. Sometimes, programming assignments consist of multiple small programs. You must write each program in a separate project. If you see an error message similar to "one or more multiply defined symbols found," chances are that you have a project with more than one file with a main function.