"The code execution cannot proceed because xxx.dll was not found" error during CMake with mingw-w64 toolchain on Windows

I am new to both LLVM and CMake, and I am trying to at least build llvm with mingw-w64 toolchain on Windows.

After typing the following command,

$ cmake -S llvm -B build \
> -DCMAKE_BUILD_TYPE=Release \
> -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc

some error windows popped up:

The code execution cannot proceed because libstdc++-6.dll was not found. Reinstalling the program may fix this problem.

Can anyone help me out? Thanks in advance.

After some research, I’ve found the solution.

During the process of CMake, it was trying to execute some binaries just to perform some checks. These binaries need some DLL’s (e.g. libstdc++-6.dll, libgcc_s_seh-1.dll, etc.) to run, and if the PATH to the DLL’s were not present, the errors in the title would show up.

Therefore, the solution is to simply add the PATH to the DLL’s. In my case, either export it in .bashrc,

export PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin:$PATH

or go to Settings->Edit the system environment variables to add the path.

Hope it helps in case someone encountered the same issue as I did.