Search code examples
c++pathincludewxwidgets

'wx/wx.h' file not found when compiling hello world wxWidget program on mac


I have just installed the latest stable version of wxWidget on my mac and tried to compile the code from the hello world tutorial. This is the code that is causing the error:

#include <wx/wxprec.h>'
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

My compiler throws the following warning:

hello_world.cpp:4:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
         ^~~~~~~~~~~~~
1 error generated.

I have checked the directory where I installed wxMac and the file wxprec.h exists in the "include" sub-directory.

If anyone knows why the file cannot be found even though it exists please let me know.


Solution

  • I found out the answer to this problem. To fix it I used the following line to compile/build the hello world app:

    g++ `wx-config --cxxflags` -o out *.cpp `wx-config --libs`
    

    after doing this it was only a matter of sorting out the linking, adding header guards and adding in

    IMPLEMENT_APP(MyApp)
    

    and

    DECLARE_APP(MyApp)
    

    in MyApp.h and MyApp.cpp respectively which functions as the main function.

    I got this information from https://wiki.wxwidgets.org/Hello_World