wxWidgets headers and libraries must be available in order to build the applications using it, so the first step when starting to use wxWidgets is to install it. This can be done, for all platforms and library versions, by building wxWidgets from sources, but for the most common platforms pre-built binaries of the libraries are also provided, so the first decision to make is whether to use these binaries or build the library yourself. Building the libraries yourself allows you to compile the latest version using exactly the options you need, and so is the most flexible solution, but using the binaries may be simpler and faster – the choice is yours, just follow the instructions in the corresponding section below depending on the approach you prefer. Of course, you only need to do one or the other, not both.
How to install binaries depends on your platform:
apt get libwxgtkX.Y-dev
.Additionally, some third-party C++ package managers also provide wxWidgets binaries. For example, please see this post for the instructions about using vcpkg C++ package manager for installing wxWidgets.
To build the library you need to get its sources first. The recommended way to do it is to use Git to check them out from the official wxWidgets repository using the following command:
$ git clone --recurse-submodules https://github.com/wxWidgets/wxWidgets.git
Alternatively, you can download the sources from the downloads page. Please note that all the source archives in different formats (ZIP, 7z, tar.bz2) contain the same files, but use different line ending formats: Unix ("LF") for the latter one and DOS ("CR LF") for the two other ones, and it is usually preferable to choose the format corresponding to the current platform. When downloading the sources with DOS ends of lines, prefer 7z format for much smaller file size.
wxWidgets can be built using CMake under all platforms. Please follow CMake build instructions if you prefer to use it.
Otherwise, please use the appropriate instructions depending on your platform:
The wxWidgets ports mentioned above are the main ones, however other variants also exist, see platform details page for the full list.
After installing wxWidgets, you need to set up your application to be built using it.
As previously, if you're using CMake, please follow the instructions for building your applications with CMake.
Note that you can use the provided samples/minimal/CMakeLists.txt
file to test building the minimal sample using CMake to verify your installation.
Otherwise, choose the appropriate method for your platform and build system:
On any Unix-like system, including macOS and Unix-like environments such as Cygwin or MSYS2 under MSW, very simple applications consisting of a single source file hello.cpp
can be built directly from the command line using the following command:
$ c++ -o hello hello.cpp `wx-config --cxxflags --libs`
Please note that you must use wx-config
to obtain the compiler and linker flags in this case. Using this method with samples/minimal/minimal.cpp
is a simple way of checking that wxWidgets is installed correctly and can be used and it is recommended to try building it, especially if you are new to wxWidgets.
For more realistic applications under Unix, a makefile is traditionally used for building. For a program consisting of the files hello.cpp
and bye.cpp
a minimal makefile could look like the following:
Please refer to the manual for more information about writing makefiles for GNU make. Also notice that you need to replace the leading spaces with TABs if you are copy-pasting the makefile above into your own.
For building applications using autoconf, you need to have the following lines in your configure.ac
file:
Note that this assumes that wxwin.m4
file is available in a standard location, as is the case when using distribution-provided wxWidgets packages or after building wxWidgets from source and using make install
. If this is not the case, you must copy this file from wxWidgets source directory to the directory containing autoconf macros used by your application (typically m4
, e.g. if you use AC_CONFIG_MACRO_DIRS([m4])
).
For applications using Microsoft Visual Studio IDE, simply add the provided wxwidgets.props
property sheet file to your project as explained in the instructions and build the project as usual.
If you want to use an environment variable (such as WXWIN) in your xcode project, there are several things you must do.
defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO
If you use an IDE with wxWidgets support, such as Code::Blocks or CodeLite, please use the IDE wizards.
If you use another IDE, under Unix you should run wx-config --cxxflags
and wx-config --libs
commands separately and copy-and-paste their output to the "Additional preprocessor options" and "Additional linker options" fields in your IDE, respectively. Under MSW systems you need to configure the IDE using the instructions in the manual setup section.