Section_02 Linux + CLion | How to make main.cpp and a second .cpp file

Hello everyone,

I was not sure if there was a specific tutorial people where we are able to follow for the Linux run through for this.
I’m not an expert by any means but I have the drive to learn both C++ and Linux at the same time and I am currently running Fedora 28 and utilizing CLion IDE for learning C++.

I want to write this guide as it will help solidify the information I am learning as well as help other newbs such as myself to be able to navigate through this course with assistance.


CLion and .cpp files

For all projects made in CLion you will be prompted to choose a directory and name of the project. Unfortunately there isn’t a way to select and name a Solution so the best work around I found was to navigate to the directory and create a folder as “Section_02” or “Solution” and move the project folder into there.

  • When a project has been created you will already have a main.cpp file in the project.
  • You may delete the main.cpp file by right clicking it along the Project menu located on the left and about half way down you will find “Delete.”
  • To add a .cpp file simply right click on the project name and select “New File” and type in “xxx.cpp”
    xxx being the name of the .cpp file. (ie. main.cpp/test.cpp)

I learned this off misunderstanding the videos but this possibly may be useful in the future. If you need two or more separate .cpp files in a project then you will need to edit the “CMakeLists.txt” file and add that .cpp file into a “add_executable”. For instance when I saw the teacher making a test.cpp file I decided to follow his lead and create it however it gave me an error saying:

  • “The file does not belong to any project target, code insight might not work properly”

This is due to the c++ file not being added to the CMakeLists.txt file and will be corrected after it is added.

Your CMakeLists.txt file should look similar to this gist:

I can’t explain why this is necessary, I suppose it may have to do with Linux needing to call the C++ compiler into the program but I’m no expert. I’ll leave this up to the pros.


I know we are further ahead than the Unreal Engine install process but I’ll explain that later when I have the time. I’ll only be posting if I find something that’s not straight forward since we are translating Windows/OSX instructions to a Linux IDE.

I deeply apologize if this post is not encouraged and I’ll refrain from posting more in the future if I’m asked to. I just felt like Linux newbs may feel as overwhelmed as I do and could use a helping hand.

Privacy & Terms