I had the exact issue and did online search and found a solution as shared by @mijen67. Its 2025 and it seems VS code came out with what i refer as a straight forward solution with less typing in their own link as shared below
https://code.visualstudio.com/docs/cpp/config-mingw
it will definitely save you several steps as shared by mijen67 in the first solution