CLion automatically adds add_executable
Install the C/C++ Single File Execution plugin, search for the C/C++ Single File Execution, find file-settings-plugins, and apply.
The preparations are complete. Next you can create a new C/ CPP file, enter the code, press Ctrl + Alt + Shift +E shortcut or right click in the code area and find Add Executable for Simple C/C++ File, then right click on the item area on the left and select Reload Cmake Project, select Auto-Reload so that it will automatically add to the executable after each right click on Add.
The C compiler identification is unknown
The environment
CLion+Cmake+Mingw
An error log
-- The C compiler identification is unknown
-- Check for working C compiler: D:/MinGW/bin/gcc.exe
-- Check for working C compiler: D:/MinGW/bin/gcc.exe -- broken
CMake Error at D:/Program Files/JetBrains/CLion 2019.2.3/bin/cmake/win/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"D:/MinGW/bin/gcc.exe"
is not able to compile a simple test program.
If it is a CPP program, it may be reported again
-- The CXX compiler identification is unknown
why
CMAKE could not check the C Compiler ID for unknown reasons, causing compilation to fail
The solution
Add the following configuration to the cMakelists.txt file to force the Compiler ID to be specified
INCLUDE(CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER(gcc GNU)
CMAKE_FORCE_CXX_COMPILER(g++ GNU)
Rerun the cmake directive after adding it