How to Fix: ‘wxMessageBox’ Was Not Declared in This Scope

I’m currently learning to write GUI applications in C++ with Code::Blocks 20.03 as my IDE. I use wxWidgets 3.0.5 as my GUI library and wxFormBuilder 3.10.1 as my GUI builder.

However, I initially encountered an issue for which I wanted to write a blog post. You see, when I built a newly-created wxWidgets project in Code::Blocks, everything worked fine. When I opened the WxWizDialogs.fbp file in wxFormBuilder, I was greeted with the following message:

Still, everything seemed to work fine. In the menu, I clicked on File and on Generate Code. Then, when I tried to build the project in Code::Blocks, I got the following error:

If you have the same problem, you can fix this error by adding the following line in the appropriate .cpp file (in my case, this was testMain.cpp):

1#include "wx/msgdlg.h"