Compile and install the wxWidgets framework in Ubuntu/Debian/Linux Mint

Source: Internet
Author: User
Tags gtk wxwidgets linux mint

WxWidgets is a C ++ development framework/library that supports cross-platform development using the same code 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>
Class Simple: public wxFrame
    {
Public:
Simple (const wxString & title)
: WxFrame (NULL, wxID_ANY, title, wxdefaposition position, wxSize (250,150 ))
        {
Centre ();
        }
};
Class MyApp: public wxApp
    {
Public:
Bool OnInit ()
        {
Simple * simple = new Simple (wxT ("Simple "));
Simple-> Show (true );
Return true;
        }
};
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/Compilingandgetting_started compiled by wxWidgets

Use the wxWidgets latest version (3.0 +) case https://wiki.wxwidgets.org/UpdatingtotheLatestVersionofwxWidgets




Two solutions for wxWidgets installation


Question 1: "Memory depletion" during compilation"


Follow the prompts of relevant materials,
(1) add F: \ Program Files \ CodeBlocks \ MinGW \ bin to the PATH variable;
(2) open the MS-DOS window and set the current directory to F: \ wxWidgets-2.8.7 \ build \ msw;
(3) run the command to compile wxWidgets:

Compilation method:


Mingw32-make-f makefile. gcc MONOLITHIC = 1 SHARED = 1 UNICODE = 1 BUILD = debug

Compilation is slow. Sadly, an error is prompted in the final result. The prompt for the last two rows is:

Gcc_mswuddll \ monodll_xh_bmpcbox.o: file not recognized: Memory exhausted
Collect2.exe: error: ld returned 1 exit status

It's actually Memory exhausted!
Without explanation, I cannot think of anything. After several keyword searches, I finally found the keyword.
How can this problem be solved?
Solution: add the-fno-keep-inline-dllexport parameter during compilation (inline symbols are not exported). In this way, the DLL file is also small, and the memory occupied by the link is also small.
Procedure:
(1) find the config. gcc file in F: \ wxWidgets-2.8.7 \ build \ msw;
(2) modify the parameters in config. gcc:


UNICODE? = 1
CPPFLAGS? =-OS-fno-keep-inline-dllexport
LDFLAGS? =-S
RUNTIME_LIBS? = Static

(3) Check the GCC version and modify the GCC version parameters.


GCC_VERSION? = 4.7.1

Run again.

No Memory exhausted


Problem 2: The file is missing in the connection

Use the wizard provided by Code: Blocks to generate a GUI application as the start of the experience.

Follow the Wizard. The generated program needs to run. There are many problems. Refer to "CodeBlocks wxWidgets compilation settings" to continue the work.
The syntax error is eliminated, except that the header file cannot be found.

The challenge lies in the connection phase.

The error message is:


Ld.exe | cannot find-lwxmsw28d_core |
Ld.exe | cannot find-lwxbase28d |
| === Build finished: 2 errors, 0 warnings (0 minutes, 1 seconds) ===

The library file cannot be found.

However, where are such library files?
View the following file in F: \ wxWidgets-2.8.7 \ lib \ gcc_dll:


Based on the searched information, lwxbase28d corresponds to libwxbase28d. a, and the expected file does not exist.
At this time, you must face up to the parameters in the command that runs during compilation.
The compilation Command is:


Mingw32-make-f makefile. gcc BUILD = release SHARED = 1 MONOLITHIC = 1 UNICODE = 1

Search to learn how to compile wxWidgets, to edit the file confg. gcc, the following options are mainly set:


SHARED = 1 compiled into a dynamic link library
UNICODE = 1 use UNICODE (I am a Chinese user, of course I want it)
BUILD = release generate official release
MONOLITHIC = 1 generate a single dynamic link library

In fact, as a preliminary experience, these parameters are too boring.
For parameter BUILD = debug, re-compile:


Mingw32-make-j2-f makefile. gcc SHARED = 1 BUILD = debug MONOLITHIC = 1 UNICODE = 1

The file added in F: \ wxWidgets-2.8.7 \ lib \ gcc_dll is


Simply change SHARED = 0 BUILD = release and run


Mingw32-make-j2-f makefile. gcc SHARED = 0 BUILD = release MONOLITHIC = 1

This time, added the F: \ wxWidgets-2.8.7 \ lib \ gcc_lib folder, where the file is:


Add F: \ wxWidgets-2.8.7 \ lib \ gcc_lib to the search directories project, Built project. It is frustrating that there are still errors. Fortunately, only cannot find-lwxbase28d is available.
Build Target is now "Debug" and try to change it to "Release ". Then Built the project. Good thing, pass, no problem. Run and run the project generated by the wizard correctly!
Change back to "Debug". The problem persists. I hope that the program of the Debug version can be compiled in my environment. This problem should be solved.
However, we can see that both SHARED = 0 and SHARED = 1 have been done in BUILD = release, no matter whether it is a dynamic link library or a static link Library, as long as the official release version (release) is generated, the existing library functions are ready. Lwxbase28d is missing. From the perspective of name, this d is exactly the meaning of debug.
Therefore, modify the parameter and compile it again. This time, a Debug library file supporting static links will be generated:


Mingw32-make-j2-f makefile. gcc SHARED = 0 BUILD = debug MONOLITHIC = 1

File:


The project can be run as soon as possible. Long live, Build Target is "Debug" and it is normal.
Record this process. You can start running the wxWidgets Demo tomorrow. After finding some feelings, read a book and try to write some small programs, which is suitable for my Cainiao students.

Experience in this installation process is: (1) don't back up when you encounter problems; (2) adjust the parameters when you are confused or cannot find out the parameters, and generate more versions. In fact, many experiences come from such testing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.