C++ Project Structure

Hello everyone, have you ever wondered while looking inside a big C++ project structure what are these different folders, subfolders, and files used for? Especially when we have just started working with C++ we get lots of questions and confusion regarding this. So let’s talk about the C++ Project Structure of a general application. 

Whenever we use an IDE like Visual Studio to generate a new C++ application, the IDE creates a bunch of different files and folders inside our project. Using an IDE to create an application will create only a basic structure. But when we work on some bigger project it’s important to organize the project directory structure properly. We will see what these different folders are used for but first let’s understand what a project structure is and why we need it.

What is a Project Structure and why should we care about it?

A project structure is basically a way to organize files under different folders in a project so that the development, testing, and deployment of an application can be managed efficiently. Dividing the whole project code into different files and keeping them under different folders can give a lot of clarity, even for other people it becomes easy to work with such a project when they are looking at the code. So now let’s see what a general C++ project structure looks like and understand different directories one by one.

Different directories in a general C++ Project Structure

C++ Project Structure
  • src/ – This is where the c++ source files are kept. When you open a c++ project you would most likely want to go inside this directory and work with the code present here or add your own code here. This contains Private source files(.h and .cpp files). 
  • bin/ – This folder contains the executable code required for the project. These are in binary format. This folder can contain files with extension .exe(for application) and .dll(for library).
  • obj/ – This folder contains intermediate object files which get generated when we compile or build all the c++ files in the src folder. After getting generated these intermediate object files then get linked together to make an executable(.exe) file.
  • include/ – Inside this folder the header files which have the .h extension are kept. These header files are Public and any other application which depends on these header files outside of this application can also use them.
  • lib/ – This folder can contain third-party libraries(.lib files) or your own library on which the project depends.
  • doc/ – If you have this folder in your project then this basically consists of the documentation of the project or some library written by the developers and maintainers of the project.
  • build/ – This folder mainly consist of the build files such as object files and executable files. Build files can be the intermediate files or the final output files which are created when the application is being built.
  • data/ – Sometimes the project you are working on has some sample/test data and configuration files(sometimes) to work with and these sample data can be stored in this folder.
  • config/ – Here we can keep the configuration files for the application. Configuration files are commonly XML files that keep some information like database connection strings. Config files are used to avoid hard-coded values in the application. Suppose you have a C++ application that is communicating with a database. Now in order to connect to the database you need to give specific credentials and in the future, if you want to change this you can directly change it in the config file and use the application without having to recompile and run it.
  • test/ – When the application is huge and there are thousands of people using it, testing is as crucial as the development of the application. In this folder, the test files are kept. Test files are used to run unit tests on the application. 

Conclusion

It’s important to understand the basic C++ project structure if you want to build or contribute to a huge application. There can be many more directories in a C++ application apart from the ones mentioned above but I hope this article offers you a rough idea of the different directories and how they link together to build an entire application.

Thank you for visiting our website.


Also Read:

Share:

Author: Ayush Purawr