DEV Community

Long Nguyễn Xuân
Long Nguyễn Xuân

Posted on

3

cách xử lý lỗi không chạy được code C++ trong Code::Blocks "Tried to run compiler enumerable `C:\MinGW/bin/gcc.exe` but failed"

Ngữ cảnh

ai học C/C++ khi chạy Hello World lần đầu trên Windows cũng thường gặp tình huống này:

bấm Build & Run thì bị báo lỗi Tried to run compiler enumerable 'C:\MinGW/bin/gcc.exe' but failed

Image description

đọc báo lỗi ta thấy đơn giản là Code::Blocks nó không tìm thấy cái GNU GCC Compiler trong đường dẫn C:\MinGW\bin\gcc.exe nên giờ mình phải "cài vào" hoặc "chỉ đường cho Code::Blocks tìm được gcc.exe"

có 2 tình huống xảy ra:

  1. bạn cài bản Code::Blocks Portable
  2. bạn cài bản Code::Blocks bình thường

trường hợp cài bản Portable

  • từ Menu, bạn chọn Settings / Compiler

Image description

  • trong cửa sổ hiện ra, chọn Toolchain executables / ở textbox Compiler's installation diretory, click vào nút 3 chấm ... rồi chọn lại đường dẫn tới folder MinGW trong cái folder

Image description

Image description

Trưởng hợp bạn cài bản Code::Blocks bình thường

vậy nên giờ mình phải "cài GNU GCC vào máy"

  1. Google "GCC Windows Install" ta sẽ được dẫn tới trang web này: https://www.geeksforgeeks.org/installing-mingw-tools-for-c-c-and-changing-environment-variable/ đây cũng là 1 trang để học C/C++ rất tốt

  2. download, cài đặt, trong lúc cài đặt ta sẽ thấy mingw sẽ được cài vào cái đường dẫn mà Code::Blocks báo là tìm không thấy lúc nãy
    Image description

  3. sau khi cài xong sẽ hiển thị màn hình mingw installer
    chọn cài các package `base
    Image description

  4. chọn apply change
    Image description
    Image description

  5. chờ một lúc
    Image description

  6. được báo là "đã cài xong" (mấy cái checkbox đổi màu xanh)
    Image description

  7. Quay lại Code::Blocks và thưởng thức
    Image description

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay