Clion Debug Trick

  1. Output is missing During Debug
    1. Method 1 insert output buf code
    2. Method 2 external terminal during debug(Recommended)
  2. How to run COMP9024 in Clion
    1. for single C file
    2. for multiple .c and .h files

Output is missing During Debug

This is because of the Clion’s console terminal, it has a large buff of output.

How to fix it?

Method 1 insert output buf code

At the beginning of the text file, add the code below:

setbuf(stdout, 0);

Edit the run configuration

Tick on the “Run in external console”, and click “Apply”

How to run COMP9024 in Clion

我在windows上,因此编译C项目我自己没有使用默认的makefile,而是自己用了CMakeList文件

The default build file of COMP9024 is makefile. In my way to run it in Clion, I choose to use MakeListfile to build instead of makefile.

Remember to install dot command, because COMP9024 often uses dot to deal with images to handle graphes. Please refer to the article Algorithm/dot-and-graph.

for single C file

Install the plugin named C/C++ Single File Execution in advance for Clion.

Open the directory which containing main, rathoer not the directory containing makefile and img.

Then right-click the directory from the file brower of Clion, create a new CMakeList.txt.

Then use the plugin function: go back to activate the tab of main.c, right-click and choose the item: Add executable for single c/cpp file.

Then CMakeList.txt would generate something, you need to right-click the file to Reload from the disk CMakeList project.

Finally, the configuration of the Run and Debug could run this file.

But it can only solve single c/cpp file, if you want to compile and run multiple .h and .c project, please refer the next section.

for multiple .c and .h files

Clear the context of CMakeList.txt, then input manually:

file(GLOB SOURCES "*.c")
add_executable(main ${SOURCES})

Then Clion could run the project successfully.


Welcome to point out the mistakes and faults!