How to compile and install wxWidgets in Ubuntu/Debian/Linux Mint
WxWidgets
WxWidgets is a program development framework/library that allows you to use the same code for cross-platform development in Windows, Mac, and Linux. It is mainly written in C ++, but can also be bound with other languages such as Python, Perl, and Ruby.
In this tutorial, I will show you how to compile wxwidgets 3.0 + In Debian-based linux such as Ubuntu and Linux Mint.
It is not difficult to compile wxWidgets from the source code. It takes only a few minutes. Libraries can be compiled in different ways, such as static or dynamic libraries.
1. Download wxWidgets
The first step is to download the wxWidgets source code file from wxwidgets.org.
Decompress the package to the directory.
2. Set the compiling environment
To compile wxwidgets, we need some tools including the C ++ compiler, Which is g ++ on Linux. All of these can be installed from the repository through the apt-get tool.
We also need the GTK development library on which wxWidgets depends.
$ sudo apt-get install libgtk-3-dev build-essential checkinstall
This tool called checkinstall allows us to create an installation package for wxwidgets, so that we can easily use the Package Manager to uninstall it.
3. Compile wxWidgets
Go to the directory decompressed by wxWidgets. Create a compilation directory to keep it clean.
$ mkdir gtk-build
$ cd gtk-build/
Run the configure and make commands. Each task will take some time to complete.
$ ../configure --disable-shared --enable-unicode
$ make
The "-- disable-shared" option will compile the static library instead of the dynamic library.
After the make command is complete, the compilation is successful. It is time to install wxWidgets to the correct directory.
For more information, see install.txtand readme.txt, which can be found in the/docs/gtk/directory in wxwidgets.
4. Install checkinstall
Now we do not use the "make install" command. We use the checkinstall command to create a deb installation package for wxwidgets. Run the following command:
$ sudo checkinstall
Checkinstall will ask several questions. Please ensure that a version number is provided after the question is asked; otherwise, it will fail.
After all this is done, wxWidgets is installed and the deb file is created in the same directory.
5. Track installed files
If you want to check the file installation location, use the dpkg command to keep up with the package name provided by checkinstall.
$ dpkg -L package_name
/.
/usr
/usr/local
/usr/local/lib
/usr/local/lib/libwx_baseu-3.0.a
/usr/local/lib/libwx_gtk3u_propgrid-3.0.a
/usr/local/lib/libwx_gtk3u_html-3.0.a
/usr/local/lib/libwxscintilla-3.0.a
/usr/local/lib/libwx_gtk3u_ribbon-3.0.a
/usr/local/lib/libwx_gtk3u_stc-3.0.a
/usr/local/lib/libwx_gtk3u_qa-3.0.a
/usr/local/lib/libwx_baseu_net-3.0.a
/usr/local/lib/libwxtiff-3.0.a
6. Compilation example
After wxWidgets is compiled, You can compile the sample program immediately. Under the same directory, a new sample directory has been created.
Enter it and run the following command
$ compile samples
$ cd samples/
$ make
After the make command is complete, enter the sample subdirectory. Here there is a Demo program that can be run immediately.
7. compile your first program
After compiling the demo program, you can write your own program to compile it. This is also very simple.
If you use C ++, you can also use the highlight feature of the editor. For example, gedit, kate, and kwrite. Or use a full-featured IDE such as Geany, Codelite, and Codeblocks.
However, you only need to use a text editor to complete your first program quickly.
As follows:
#include<wx/wx.h>
classSimple:public wxFrame
{
public:
Simple(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250,150))
{
Centre();
}
};
classMyApp:public wxApp
{
public:
boolOnInit()
{
Simple*simple =newSimple(wxT("Simple"));
simple->Show(true);
returntrue;
}
};
wxIMPLEMENT_APP(MyApp);
Save and compile it with the following command.
# compile
$ g++ basic.cpp `wx-config --cxxflags --libs std`-o program
# run
$ ./program
Compilation with non-standard Libraries
By default, the wx-config command shown in the preceding figure only supports standard libraries. If you are using the Aui library, you need to specify the library for additional use.
$ g++ code.cpp `wx-config --cxxflags --libs std,aui`-o program
For more information, see here.
Resources
Download wxWidgets source code and help https://www.wxwidgets.org/downloads/
Wiki page https://wiki.wxwidgets.org/Compiling compiled by wxWidgetsAndGetting_started
Use the wxWidgets latest version (3.0 +) Case https://wiki.wxwidgets.org/UpdatingToTheLatestVersionOfWxWidgets
WxWidgets details: click here
WxWidgets: click here
Configure wxWidgets/OpenGL and mixed programming for OpenCV in Ubuntu
Code: Blocks + wxWidgets 2.9.3 in Ubuntu