Search code examples
c++wxwidgets

How to correctly 'install' wxWidgets on a Mac


I have been trying for a while to get the wxWidgets library working on my Mac, but I have been having tons of issues. I have tried both downloading the source and building it myself and using Homebrew.

I have gotten to the point where I can compile the following:

helloworld.hpp:

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

class HelloWorldApp : public wxApp {
public:
    virtual bool OnInit();
};

DECLARE_APP(HelloWorldApp)

helloworld.cpp:

#include "helloworld.hpp"


IMPLEMENT_APP(HelloWorldApp)

bool HelloWorldApp::OnInit() {
    wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Hello wxWidgets World"));
    frame->CreateStatusBar();
    frame->SetStatusText(_T("Hello World"));
    frame->Show(true);
    SetTopWindow(frame);
    return true;
}

I use g++ helloworld.cpp `wx-config --cxxflags --libs` -o hello to compile it. This seems to work, and g++ doesn't report any errors or warnings.

However, as soon as I try to run it (./hello) I get a lot of errors, most of which go like:

objc[92442]: Class wxNSSomething is implemented in both
/usr/local/Cellar/wxmac/3.0.5.1_1/lib/something.dylib (0x10bd00c50)
and /usr/local/opt/wxmac/lib/something.dylib (0x10b329c50). One of the two
will be used. Which one is undefined.

and

./src/common/object.cpp(251): assert "classTable->Get(m_className) == NULL" 
failed in Register(): Class "wxSomething" already in RTTI table - 
have you used IMPLEMENT_DYNAMIC_CLASS() multiple times or linked some object file twice)?

...finally ending with a segmentation fault.

It seems to me that I have two versions installed in two different at the same time (hence the "Class is implemented in both ... and ..."). But if I uninstall the Hombrew one, it gets rid of things that cause the compilation to fail.

I've tried various potential fixes from the internet but none of them have worked.

I'm not really sure what to do here. Has anyone else experienced this before? What should I do to fix it?

My Mac is Intel and running MacOS 11.2.3.


Solution

  • @scriptor6,

    Get rid of homebrew install.

    Get rid of the one you compiled

    Download latest release of the library from wxwidgets.org/downloads.

    Unpack it somewhere.

    Do this

    cd wxwidgets-3.1.4
    mkdir buildOSX
    cd buildOSX
    ../configure --enable-debug
    make
    cd samples/minimal
    make
    open minimal.app
    

    If at any point you will get an error- let us know with the complete error message cut'n'pasted as it appeared

    HTH.