The preLaunchTask 'build debug' terminated with exit code 2 Error

Hi, I´m currently stuck at the very begginng of the axe game section. When I try to Run my code the following message appears on my screen:

It says that The preLaunchTask ‘build debug’ terminated with exit code 2, and when I click on Debug anyway it asks me to open launch.json but nothing else happens later.

One thing that I tried was deleting my hello.cpp file and it somehow fixed the issue but I don´t see this as a good solution. Can someone help me solve this error without having to delete my files? Thx.

1 Like

Deleting hello.cpp is actually the correct solution for this kind of error.

The main function in C++ represents the start of our program, and the compiler tries to compile all cpp files in our project. So when it finds two files with the main function defined it gets confused and throws an error, cause the compilation of our code to fail.

If you’re wanting to keep hello.cpp, then moving it to a new project is the other option. But both hello.cpp and axe-game.cpp cannot be in the same project if both define the main function.

1 Like

Thank you so much for answering my question! It makes a lot of sense now that you say it.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms