You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CLion生成的EXE文件无法打开,缺失libgcc等DLL问题求助

Fixing Missing libgcc_s_sjlj-1.dll and libstdc++-6.dll in CLion-Generated EXEs

Hey there, I’ve dealt with this exact issue when using MinGW with CLion, so let’s break down the problem and solutions clearly—no overly technical jargon needed.

Why This Happens

By default, when you compile a C/C++ project in CLion (using MinGW), the linker uses dynamic linking for libraries like libgcc and libstdc++. That means your EXE doesn’t include the code from these libraries directly; instead, it looks for the corresponding DLL files at runtime. If those DLLs aren’t in your system’s PATH or the same folder as the EXE, you get that error.

What -static Does (In Plain English)

The -static flag tells the linker to use static linking instead. Instead of relying on external DLLs, it copies all the necessary code from libgcc and libstdc++ directly into your EXE file. This makes the EXE larger, but it runs independently without needing those DLLs present on the target machine.

Step-by-Step Solutions

This is the cleanest fix if you want to share your EXE without extra files. Here’s how to set it up in CLion:

  1. Open your project’s CMakeLists.txt file.
  2. Add the static linking flags to your target. You have two ways to do this:
    • Target-specific setup (better practice, only applies to your project):
      add_executable(YourProjectName main.cpp) # Replace with your actual target name
      target_link_libraries(YourProjectName PRIVATE -static -static-libgcc -static-libstdc++)
      
    • Global setup (applies to all targets in the project):
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc -static-libstdc++")
      
  3. Click the Reload CMake Project button (the refresh icon in the CMake toolbar) to apply the changes.
  4. Recompile your project. The new EXE will include all necessary library code and run without missing DLLs.

Option 2: Copy the Missing DLLs to the EXE Folder

If you don’t want to static link (e.g., to keep the EXE size smaller), you can manually copy the DLLs:

  • Locate your MinGW installation directory (e.g., C:\mingw64\bin for 64-bit MinGW).
  • Find libgcc_s_sjlj-1.dll and libstdc++-6.dll in the bin folder.
  • Copy both files into the same directory as your generated EXE.
  • Now your EXE should run normally, as it can find the DLLs right next to it.

Quick Notes

  • The -static-libgcc and -static-libstdc++ flags are more precise than just -static—they only static link the GCC and C++ standard libraries, leaving other system libraries (like Windows APIs) as dynamic links (which is usually what you want).
  • If you’re using a different compiler toolchain (not MinGW), the steps might vary slightly, but the core idea of static linking vs. copying DLLs still applies.

内容的提问来源于stack exchange,提问作者Szymon Gajdzica

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:53:27