I tried defining the path in Settings/Compiler/Search Directories and where it says Compiler I used C:\Program Files (x86)\CodeBlocks\MinGW\bin. I still get the same error. What am I doing wrong?
It's not "Settings -> Compiler -> Global compiler settings -> GNU GCC compiler -> Search Directories" (that's for include-files and need not to be set in normal cases, because the compiler knows where it is), but "Settings -> Compiler -> Global compiler settings -> GNU GCC compiler -> Toolchain executables" (the next tab on the right side, it might be hidden, but in this case, you have a little black triangle at the right side of the tabs to click on).
On the appropriate tab, set the "Compiler's installation directory" (without the bin) and make sure the names of the executables are correct. On windows it can be (e.g.) either "gcc" or "mingw32-gcc".