求助:Windows版CLion 2019.1新建项目无法运行(新手咨询)
Hey there! I totally get it—diving into CLion and C programming as a newbie can feel frustrating when things don’t work right away. Let’s break down the most common reasons your project isn’t running, with simple, jargon-light fixes.
1. You’re Missing a C Compiler (The #1 Culprit!)
CLion doesn’t come with its own C compiler—it needs external tools like MinGW-w64 or MSVC to build your code. Here’s how to check and fix this:
- Open CLion, go to
File > Settings > Build, Execution, Deployment > Toolchains. - If you don’t see any configured toolchains (no green checkmark next to an entry), you need to install a compiler:
- Grab MinGW-w64 (pick the x86_64 version for 64-bit Windows, or i686 for 32-bit).
- Install it to a path with no spaces (like
C:\mingw64—avoidProgram Filesbecause spaces can mess with toolchain detection). - Back in Toolchains settings, click the
+button, selectMinGW, then browse to your MinGW installation’sbinfolder (e.g.,C:\mingw64\bin) so CLion can findgcc.exe,g++.exe, andmake.exe. - Hit
Applyto save your setup.
2. CMake Isn’t Using Your Configured Toolchain
Even if you installed a compiler, CLion might not be telling CMake to use it:
- Go to
File > Settings > Build, Execution, Deployment > CMake. - Under
Profile, make sure theToolchaindropdown is set to the MinGW (or MSVC) toolchain you just set up. - Click
Reload CMake Project(the refresh icon in the top-right of the CMake tool window, or useCtrl+Shift+F5shortcut).
3. Double-Check Your main.c Code
Sometimes the default template gets accidentally modified, or you added code with syntax errors:
- Open
main.cand confirm it matches the working default template:#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } - Look for red underlines—those are syntax errors. Fix them, then try building again.
4. Ensure a Run Configuration Exists
If the Run button is grayed out, CLion might not have auto-generated a run config:
- First, try building your project: go to
Build > Build Project(or pressCtrl+F9). - If the build succeeds, the Run button should light up. If not:
- Go to
Run > Edit Configurations. - Click the
+button, selectApplication. - In the
Targetdropdown, pickuntitled4(your project name). - Hit
ApplyandOK, then try running again.
- Go to
Quick Debugging Tip
If none of these work, check the Build or CMake tool windows at the bottom of CLion. They’ll show specific error messages (like "gcc not found") that will point you straight to the problem.
内容的提问来源于stack exchange,提问作者J. Doe

