Search code examples
c++visual-studio-codeg++clangmingw

How do I set path to respective bin of the mingw directory


I'm trying to use C++ in VSCode, and I found a tutorial where I install g++ and clang to make it work.

I installed g++ fine, and added it to my list of environment variables, but then the instructions for installing clang say to "set path to respective bin of the mingw directory" without showing me how.

What does this mean and how do I do that?

Also, #include <iostream> looks like it doesn't work either, it says the file is not found, so I'm wondering if it's because clang isn't installed or something else I need to fix. Thanks!


Solution

  • Ok, I've skimmed that tutorial video and YouTube comment section. Basically I think it's a poor tutorial, as it doesn't explain the basics, and that's why you're getting tripped up. My first recommendation is to save yourself some trouble and follow the VSCode Getting Started with C++ Tutorial instead.

    Not only is the official tutorial easier to understand, it will guide you toward using the Microsoft C++ extension that almost everyone uses (and can help you with), rather than the comparatively obscure Clang-based C++ extension.

    But that's not answer to your actual question. You asked:

    ... the instructions for installing clang say to "set path to respective bin of the mingw directory" without showing me how.

    What does this mean and how do I do that?

    I'm not sure! It's sort of nonsensical. But I think what is meant is:

    1. Install mingw GCC and put its bin directory on the PATH.
    2. Install LLVM+Clang and put its bin directory on the PATH.
    3. Start VSCode from a shell where both are on the PATH.
    4. Then proceed with the linked tutorial.

    You say you already have mingw GCC on your path, but let's check that. At the command prompt (I assume you are using the default Windows cmd.exe shell), run:

    > gcc --version
    gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 5.4.0
    Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

    If you don't see output like that, then something is wrong. Make sure the bin directory of mingw GCC, which contains gcc.exe, is on your PATH.

    Next, Clang. Clang is part of LLVM. Wherever you installed LLVM, there should be a bin directory inside it containing clang.exe. Add that to your PATH. In my case, I installed LLVM into d:\opt\llvm-8.0.1, so I would run:

    > set PATH=%PATH%;d:\opt\llvm-8.0.1\bin
    

    Then check that it is working:

    > clang --version
    clang version 8.0.1 (tags/RELEASE_801/final)
    Target: x86_64-pc-windows-msvc
    Thread model: posix
    InstalledDir: D:\opt\llvm-8.0.1\bin
    

    Once both gcc --version and clang --version respond similarly to what I have shown, you're ready to start VSCode:

    > code
    

    and from there, the tutorial's instructions should work.