C/C++ Single File Execution Plugin

CLion Plugin to run single file easily

CLion plugin to execute single file .c/.cpp file quickly.

CLion is a C/C++ IDE on IntelliJ IDEA platform provided by JetBrains, and it is working on CMake platform. When you want to run a single file with main() function, you need to configure CMakeLists.txt file everytime. This plugin helps you to add this configuration (the code of add_executable() ) automatically to quickly run a single .c/.cpp file.

Please go to github page for details.


Use case

If you are CLion lover, you may want to edit a easy C/C++ file using CLion. However, CLion compile tool only works when CMakeLists.txt is configured properly. Concretely, below code must be added to CMakeLists.txt.

This plugin automatically adds this code, so that you can easily run a single C source code!

Especially, I think this is useful for programming contest (competitive programming) where you want to make many single C/C++ source file to be executed in a single file.




In the above project, I have a hoge/bar.cpp which contains main() function. It can be run independently, (no dependency with main.cpp or sub.cpp). To build and run this in CLion, we must add below code to CMakeLists.txt

This plugin add this one line automatically!

Note that CLion’s auto-complete feature and auto-compile check runs only when this CMakeLists are configured properly. (e.g. including vector header file is suggested in above picture)


C/C++ Single File Execution plugin is uploaded on JetBrains repositry, so you can download by navigating [File] → [Settings] → [Plugins] tab → click [Browse repositries…] in CLion.

You can find and install C/C++ Single File Execution plugin.



How to use

  1. Create or show C/C++ source code you want to run on the editor.
  2. Right click on the editor.
  3. Select “Add executable for single c/cpp file”.

That’s all! Plugin automatically insert add_executable to CMakeLists.txt with proper path for you.


After that, you can start coding and once it’s done, run it by selecting proper executable name on the top-right panel in CLion.




Little configuration is available from [File]  → [Settings] → [Tools] tab > [Single File Execution Plugin].

executable name

You may specify the executable name. As a default with %FILENAME%, it will use a name depending on the source code file name. In this case, every time you add a new source code and insert add_executable, new executable name will be added. Build configuration tab can be messy in this case as the number of files increases.

Another way is to use “fixed” executable name here (not use %FILENAME%), in that case you can always run single source code file with same executable name.

runtime output directory

You can also specify a directory where the executable file will be stored after build.

For example, when you set %FILEDIR%, executable file will be located in the same directory of source file. This configuration is especially useful when your source code reads/writes another file which is located in same directory of the source file.


Concrete example is for programming contest. You may want to read the input data from another text file. You can just place the input data text file in the same directory of source file, and just write below

you can now build and run this program by pressing “run” button on CLion.

Sponsored Links

5 responses

  1. Yes! This is just what I needed! I think this should be added to the program, it doesn’t make sense that it isn’t. Thank you.

  2. Hey corochann, thank you for sharing it with us. Really helpful. Also, if you could integrate another feature that will be greatly helpful, may be in later versions.

    I like to run only single file most of the time. So, when I select “Add executable for single c/cpp file” it will update the CMakeLists.txt file to contain only the current file in add_executable() list and no other. May be it could a optional feature who like to use it.

    • Thanks for feedback.
      What you want to do can be achieved by setting executable name to for example “single_file_exe”, instead of %FILENAME% as written in this blog?
      Then, it will always overwrite executable name, so that only one executable name remains.

Leave a Reply to Nick Cancel reply

Your email address will not be published.