Add a new executable to project
In this procedure we will create a new executable file in your project. To be able to have more than one executable file in a project, it is necessary to complete this procedure. After completion, the new executable file should be able to be run by CLion.
Pre-requisites
Before starting this procedure, you must have an existing project. If you do not, please create a new project.
Instructions
Open CLion.
You should now be in the [starting window].
Click on your project to open it.
You should be now in the [main window].
Right-click the project’s directory.
Hover across New > C/C++ Source File.
Enter the name of your new file in the Name box.
Click the desired type of file from the Type drop down menu, then click Ok.
* We will use a .c file (C source file) for demonstration purposes, but CLion also supports .cpp files (for C++ source files)
Double-click CMakeLists.txt to open it.
The source code should now appear in the code pane of the [main window].
Type “add_executable()” in a new line.
Inside the parenthesis, type:
- the name of your app followed by a space,
- the relative path to your executable file from the “CMakeList.txt”.
Click Reload changes.
Congratulations! You have successfully added a new executable to your project. Next, perform the success check below. If you have any issues, check out troubleshooting. Then, continue to add Github to CLion
✓ Check for success: After this stage you should be able to find the new executable in the executables list.