C/C++ wxWidgets Development Files

Leveret

Member

Reaction score: 6
Messages: 71

I've scoured the other threads and rest of Internet but haven't seen anything that would help to get wxWidgets working on FreeBSD when using C programming. I wasn't able to do this on Linux until I installed developer files. Is this the same with FreeBSD? Python works fine with wxWidgets on FreeBSD. Trying to get the HelloWorldApp program from their website to work with C code produces a complaint about wx/wxprec.h not being found. I want to also write in C. I'm kinda new to this. Any help would be greatly appreciated.
 

kpedersen

Daemon

Reaction score: 582
Messages: 1,512

A couple of hints that might help:

  • In FreeBSD, there is no *-dev packages. Installing the package (or port) includes the developer files.
  • wxWidgets is packaged as wx-gtk or something like that. Your best bet is when finding out what the config program is called, do a:
Code:
find /usr/local/bin | grep wx
Then use this in place of wx-config
  • Remember, wxWidgets is written in C++, not C. You also need to use C++ to interface with it.
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 71

This is what I get from find /usr/local/bin | grep wx:
/usr/local/bin/wxrc-gtk2u-2.8
/usr/local/bin/pywxrc

I tried a couple of things.

$ gcc6 HelloWorldApp.cpp `wx-config --libs` `wx-config --cxxflags` -o HelloWorldApp
This produces the error saying that wx/wxprec.h is not found.

$ clang++ HelloWorldApp.cpp `wxgtk2u-2.8-config --libs` `wxgtk2u-2.8-config --cxxflags` -o HelloWorldApp
Then I used the above command. Not sure if I understood you correctly. It gives many more errors. Also, the g++ compiler was recommended on sites that I looked at. I couldn't see how to install it. Is clang a good enough substitute?

As I said, I am new to all of this.
 

ljboiler

Well-Known Member

Reaction score: 113
Messages: 365

The name is slightly changed in the FreeBSD wxWidgets packages: instead of wx-config, it's called wxgtk2u-2.8-config (for wxWidgets version 2.8), and should be in /usr/local/bin.
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 71

You're right, it is in /usr/local/bin. This usage doesn't work: $ clang++ HelloWorldApp.cpp `wxgtk2u-2.8-config --libs` `wxgtk2u-2.8-config --cxxflags` -o HelloWorldApp. Assuming that my usage of clang is correct, I still need to understand how to use wxgtk2u-2.8-config. Any ideas?
 
D

Deleted member 45312

Guest


It works for me, with wx28-gtk2-2.8.12 and wx30-gtk2-3.0.2 installed. I am having a lot of warnings from clang++ but the executable is built and I can run it.
What is your error output ?
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 71

wx-config: Command not found.
wx-config: Command not found.
HelloWorldApp.cpp:3:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
^~~~~~~~~~~~~
1 error generated.

Then I get:

clang++ HelloWorldApp.cpp `wxgtk2u-2.8-config --libs` `wxgtk2u-2.8-config --cxxflags` -o HelloWorldApp
HelloWorldApp.cpp:25:1: error: unknown type name 'wxIMPLEMENT_APP'
wxIMPLEMENT_APP(MyApp);
^
HelloWorldApp.cpp:33:11: error: no matching constructor for initialization of 'wxFrame'
: wxFrame(NULL, wxID_ANY, "Hello World")
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/gtk/frame.h:33:5: note: candidate constructor not viable: no known
conversion from 'const char [12]' to 'const wxString' for 3rd argument
wxFrame(wxWindow *parent,
^
/usr/local/include/wx-2.8/wx/gtk/frame.h:28:24: note: candidate constructor
(the implicit copy constructor) not viable: requires 1 argument, but 3 were provided
class WXDLLIMPEXP_CORE wxFrame : public wxFrameBase
^
/usr/local/include/wx-2.8/wx/gtk/frame.h:32:5: note: candidate constructor not viable: requires 0
arguments, but 3 were provided
wxFrame() { Init(); }
^
HelloWorldApp.cpp:36:15: error: no matching member function for call to 'Append'
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
~~~~~~~~~~^~~~~~
/usr/local/include/wx-2.8/wx/menu.h:62:17: note: candidate function not viable: no known
conversion from 'const char [17]' to 'const wxString' for 2nd argument
wxMenuItem* Append(int itemid,
^
/usr/local/include/wx-2.8/wx/menu.h:312:17: note: candidate function not viable: no known
conversion from 'const char [17]' to 'const wxString' for 2nd argument
wxMenuItem* Append(int itemid,
^
/usr/local/include/wx-2.8/wx/menu.h:303:10: note: candidate function not viable: requires 4
arguments, but 3 were provided
void Append(int itemid,
^
/usr/local/include/wx-2.8/wx/menu.h:99:17: note: candidate function not viable: requires single
argument 'item', but 3 arguments were provided
wxMenuItem* Append(wxMenuItem *item) { return DoAppend(item); }
^
HelloWorldApp.cpp:43:32: error: reference to type 'const wxString' could not bind to an lvalue of
type 'const char [6]'
menuBar->Append( menuFile, "&File" );
^~~~~~~
/usr/local/include/wx-2.8/wx/gtk/menu.h:27:56: note: passing argument to parameter 'title' here
virtual bool Append( wxMenu *menu, const wxString &title );
^
HelloWorldApp.cpp:44:32: error: reference to type 'const wxString' could not bind to an lvalue of
type 'const char [6]'
menuBar->Append( menuHelp, "&Help" );
^~~~~~~
/usr/local/include/wx-2.8/wx/gtk/menu.h:27:56: note: passing argument to parameter 'title' here
virtual bool Append( wxMenu *menu, const wxString &title );
^
HelloWorldApp.cpp:47:20: error: reference to type 'const wxString' could not bind to an lvalue of
type 'const char [22]'
SetStatusText( "Welcome to wxWidgets!" );
^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/frame.h:110:48: note: passing argument to parameter 'text' here
virtual void SetStatusText(const wxString &text, int number = 0);
^
HelloWorldApp.cpp:48:10: error: use of undeclared identifier 'wxEVT_MENU'
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
^
HelloWorldApp.cpp:49:10: error: use of undeclared identifier 'wxEVT_MENU'
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
^
HelloWorldApp.cpp:50:10: error: use of undeclared identifier 'wxEVT_MENU'
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
^
HelloWorldApp.cpp:58:5: error: no matching function for call to 'wxMessageBox'
wxMessageBox( "This is a wxWidgets' Hello world sample",
^~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/msgdlg.h:70:17: note: candidate function not viable: no known
conversion from 'const char [40]' to 'const wxString' for 1st argument
int WXDLLEXPORT wxMessageBox(const wxString& message,
^
HelloWorldApp.cpp:63:5: error: no matching function for call to 'wxLogMessage'
wxLogMessage("Hello world from wxWidgets!");
^~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/log.h:546:1: note: candidate function not viable: no known
conversion from 'const char [28]' to 'const wxChar *' (aka 'const wchar_t *') for 1st
argument
DECLARE_LOG_FUNCTION(Message);
^
/usr/local/include/wx-2.8/wx/log.h:494:30: note: expanded from macro 'DECLARE_LOG_FUNCTION'
extern void WXDLLIMPEXP_BASE wxLog##level(const wxChar *szFormat, \
^
<scratch space>:209:1: note: expanded from here
wxLogMessage
^
11 errors generated.

HelloWorldApp.cpp:25:1: error: unknown type name 'wxIMPLEMENT_APP'
wxIMPLEMENT_APP(MyApp);
^
HelloWorldApp.cpp:33:11: error: no matching constructor for initialization of 'wxFrame'
: wxFrame(NULL, wxID_ANY, "Hello World")
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/gtk/frame.h:33:5: note: candidate constructor not viable: no known
conversion from 'const char [12]' to 'const wxString' for 3rd argument
wxFrame(wxWindow *parent,
^
/usr/local/include/wx-2.8/wx/gtk/frame.h:28:24: note: candidate constructor
(the implicit copy constructor) not viable: requires 1 argument, but 3 were provided
class WXDLLIMPEXP_CORE wxFrame : public wxFrameBase
^
/usr/local/include/wx-2.8/wx/gtk/frame.h:32:5: note: candidate constructor not viable: requires 0
arguments, but 3 were provided
wxFrame() { Init(); }
^
HelloWorldApp.cpp:36:15: error: no matching member function for call to 'Append'
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
~~~~~~~~~~^~~~~~
/usr/local/include/wx-2.8/wx/menu.h:62:17: note: candidate function not viable: no known
conversion from 'const char [17]' to 'const wxString' for 2nd argument
wxMenuItem* Append(int itemid,
^
/usr/local/include/wx-2.8/wx/menu.h:312:17: note: candidate function not viable: no known
conversion from 'const char [17]' to 'const wxString' for 2nd argument
wxMenuItem* Append(int itemid,
^
/usr/local/include/wx-2.8/wx/menu.h:303:10: note: candidate function not viable: requires 4
arguments, but 3 were provided
void Append(int itemid,
^
/usr/local/include/wx-2.8/wx/menu.h:99:17: note: candidate function not viable: requires single
argument 'item', but 3 arguments were provided
wxMenuItem* Append(wxMenuItem *item) { return DoAppend(item); }
^
HelloWorldApp.cpp:43:32: error: reference to type 'const wxString' could not bind to an lvalue of
type 'const char [6]'
menuBar->Append( menuFile, "&File" );
^~~~~~~
/usr/local/include/wx-2.8/wx/gtk/menu.h:27:56: note: passing argument to parameter 'title' here
virtual bool Append( wxMenu *menu, const wxString &title );
^
HelloWorldApp.cpp:44:32: error: reference to type 'const wxString' could not bind to an lvalue of
type 'const char [6]'
menuBar->Append( menuHelp, "&Help" );
^~~~~~~
/usr/local/include/wx-2.8/wx/gtk/menu.h:27:56: note: passing argument to parameter 'title' here
virtual bool Append( wxMenu *menu, const wxString &title );
^
HelloWorldApp.cpp:47:20: error: reference to type 'const wxString' could not bind to an lvalue of
type 'const char [22]'
SetStatusText( "Welcome to wxWidgets!" );
^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/frame.h:110:48: note: passing argument to parameter 'text' here
virtual void SetStatusText(const wxString &text, int number = 0);
^
HelloWorldApp.cpp:48:10: error: use of undeclared identifier 'wxEVT_MENU'
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
^
HelloWorldApp.cpp:49:10: error: use of undeclared identifier 'wxEVT_MENU'
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
^
HelloWorldApp.cpp:50:10: error: use of undeclared identifier 'wxEVT_MENU'
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
^
HelloWorldApp.cpp:58:5: error: no matching function for call to 'wxMessageBox'
wxMessageBox( "This is a wxWidgets' Hello world sample",
^~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/msgdlg.h:70:17: note: candidate function not viable: no known
conversion from 'const char [40]' to 'const wxString' for 1st argument
int WXDLLEXPORT wxMessageBox(const wxString& message,
^
HelloWorldApp.cpp:63:5: error: no matching function for call to 'wxLogMessage'
wxLogMessage("Hello world from wxWidgets!");
^~~~~~~~~~~~
/usr/local/include/wx-2.8/wx/log.h:546:1: note: candidate function not viable: no known
conversion from 'const char [28]' to 'const wxChar *' (aka 'const wchar_t *') for 1st
argument
DECLARE_LOG_FUNCTION(Message);
^
/usr/local/include/wx-2.8/wx/log.h:494:30: note: expanded from macro 'DECLARE_LOG_FUNCTION'
extern void WXDLLIMPEXP_BASE wxLog##level(const wxChar *szFormat, \
^
<scratch space>:209:1: note: expanded from here
wxLogMessage
^
11 errors generated.

I installed wx30-gtk2 and still got these messages. wx28-gtk2 was already installed.
 
D

Deleted member 45312

Guest


Then I get:

clang++ HelloWorldApp.cpp `wxgtk2u-2.8-config --libs` `wxgtk2u-2.8-config --cxxflags` -o HelloWorldApp
HelloWorldApp.cpp:25:1: error: unknown type name 'wxIMPLEMENT_APP'
wxIMPLEMENT_APP(MyApp);
I can build this sample code with wx30-gtk2-3.0.2 with warnings but no errors.
It does not build with wx28-gtk2-2.8.12.
There is some changes since wx28-gtk2-2.8.12 and the HelloWorld.app from wxWidgets web site is for wxWidgets 3.1.1

You can try the following sample code which build with the two releases :
Code:
// Name:        minimal.cpp
// Purpose:     Minimal wxWidgets sample
// Author:      Julian Smart

#include "wx/wx.h"

// Declare the application class
class MyApp : public wxApp
{
public:
    // Called on application startup
    virtual bool OnInit();
};

// Declare our main frame class
class MyFrame : public wxFrame
{
public:
    // Constructor
    MyFrame(const wxString& title);

    // Event handlers
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);

private:
    // This class handles events
    DECLARE_EVENT_TABLE()
};

// Implements MyApp& GetApp()
DECLARE_APP(MyApp)

// Give wxWidgets the means to create a MyApp object
IMPLEMENT_APP(MyApp)

// Initialize the application
bool MyApp::OnInit()
{
    // Create the main application window
    MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App"));

    // Show it
    frame->Show(true);

    // Start the event loop
    return true;
}

// Event table for MyFrame
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
    EVT_MENU(wxID_EXIT,  MyFrame::OnQuit)
END_EVENT_TABLE()

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg;
    msg.Printf(wxT("Hello and welcome to %s"),  
               wxVERSION_STRING);

    wxMessageBox(msg, wxT("About Minimal"),
                 wxOK | wxICON_INFORMATION, this);
}

void MyFrame::OnQuit(wxCommandEvent& event)
{
    // Destroy the frame
    Close();
}

#include "mondrian.xpm"

MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title)
{
    // Set the frame icon
    SetIcon(wxIcon(mondrian_xpm));

    // Create a menu bar
    wxMenu *fileMenu = new wxMenu;

    // The "About" item should be in the help menu
    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
                     wxT("Show about dialog"));

    fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"),
                     wxT("Quit this program"));

    // Now append the freshly created menu to the menu bar...
    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, wxT("&File"));
    menuBar->Append(helpMenu, wxT("&Help"));

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);

    // Create a status bar just for fun
    CreateStatusBar(2);
    SetStatusText(wxT("Welcome to wxWidgets!"));
}
 
D

Deleted member 45312

Guest


You can get those samples from the original wxGTK tarball on the main web site.
 
OP
OP
L

Leveret

Member

Reaction score: 6
Messages: 71

Diegrand, I was able to build the sample that you said compiled with the two releases after commenting out two references to mondrian.xpm. I have wx30-gtk2-3.0.2 and wx28-gtk2-2.8.12 installed. I used this command: clang++ HelloWorldApp.cpp `wxgtk2u-3.0-config --libs` `wxgtk2u-3.0-config --cxxflags` -o HelloWorldApp. Thank you for explaining to me that the website is using programs for wxWidgets 3.1.1. In my rush to find answers I neglected to notice this. I also will look at the manuals. I'm happy that I have it working. I will look more into this now and can confidently remove that Linux install and stick with FreeBSD. I only kept the Linux install because I managed after previous failures to get it working on Linux. That's to everyone who helped. Much appreciated.
 
Top