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.
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.
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.