Configure code: blocks + wxWidgets on Windows

Source: Internet
Author: User
Tags wxwidgets
Document directory
  • Compiler
  • The latest code: Blocks
  • WxWidgets
  • Compile wxWidgets
  • Build
  • Shared
  • Monolithic
  • Unicode
  • Error similar to "wx/setup. h: no such file or directory"
  • Error similar to "cannot find-lwxmsw28u"
Configure code: blocks + wxWidgets on Windows

On the evening of the 27th, I asked a friend of shared software, lazaru (based on freepascal's cross-platform IDE, similar to Delphi) How to Do desktop software. He recommended code: blocks, it is said that the build is stable and the official version will soon be released, and the official version will be released on the 28 th.

This article is from the wxwindowsquickref on code: blocks wiki.
The content of this article is not completely translated word by word according to the original text.

Code: Blocks
Is a cross-platform C ++ ide that supports windows, Linux, and MacOSX. It also supports various compilers, such as GNU/mingw C/C ++, VC ++ 6.0/2003/2005/2008, Borland C ++, digital Mars and other different compilers.

After two years of rewriting code: blocks by 14 members, the official version 8.02 was released. This version also includes support for building wxWidgets-based cross-platform GUI programs, similar to Visual C ++.

WxWidgets
It is a very good cross-platform GUI framework. The C ++ applications compiled by it can be easily migrated to different systems.

Code: blocks +
WxWidgets supports cross-platform IDE and framework, making cross-platform programming very convenient. However, code: Although blocks supports wxWidgets,
However, wxWidgets is not included in the build environment. We must configure it manually. In addition, code: blocks has an installation package containing the mingw compiler.
You also need to configure the compiler.

Prerequisites Compiler

At least you should have installed the free mingw/GCC compiler correctly.
Or a Microsoft compiler.
(Express editions
It is free, but you still need to install Platform SDK
). For mingw/GCC, at least prepare the GCC-core, GCC-G ++, binutils, w32api, and mingw32-make packages; and ensure that the directory contains the executable files of the compiler (typicallyC:/MinGW/bin
In the PATH environment variable of windows.

If you select the mingw/GCC compiler, you can directly select the code: blocks installation package containing mingw, as shown in the next section.

The latest code: Blocks

Please download the latest 8.02 release
. You can select an installation package containing mingw if you have not selected a compiler.
.

WxWidgets

You can download the source code of wxWidgets and build it by yourself, or directly install the pre-compiled wxpack.

WxWidgets source code

The installation package is small and can be customized as needed, but it takes a long time to compile. If you do not know the compilation options, you may fail to configure code: blocks.

Currently, the recommended wxWidgets version is 2.8.7. Click here to download the wxWidgets 2.8.7 source code Windows Installation Package
(Wxmsw-2.8.7-setup.exe; 12.0 MB ). You can also check the wxWidgets download page.
Check whether there is any stable version download.We strongly recommend that you install the code in a path without spaces.
Ensure that the disk has at least MB of free space.

Wxpack

Although the installation package is up to 200 MB, it requires 3 GB for all installation, but it contains all the library files that may be used in pre-compilation, and contains two versions of VC and GCC, you don't have to consider the build options.

The current stable release version of wxpack is v2.8.7.03 Based on wxWidgets 2.8.7. Click here to download wxpack v2.8.7.03
(Wxpack_v2.8.7.03.exe, 236.9 MB ). You can also view the wxpack Download Page
Check whether there is any stable version download.We strongly recommend that you install wxpack in a path without spaces.
If you select msvc only, ensure that at least MB of space is available. If you only select mingw/GCC, ensure that at least GB of space is available.

Prompt

If the disk uses the NTFS format, you can enable the File compression function. The preceding directory can reduce the space usage by 50% after compression.

Compile wxWidgets

You can skip this step by using wxpack.

Open the command line (click "run" in the Start Menu, Enter cmd, and press Enter ). If msvc is used, you can use a specific command line for setting environment variables. If you use
Msvc also requires you to download the Platform SDK separately to ensure that all environment variables used in the standard compilation tool and platform SDK are included.

Go to the wxWidgets build directory, where <wxWidgets> is the source code path, usuallyC:/wxWidgets-2.8.7
:

cd <wxWidgets>/build/msw

Execute the build command,Mingw/GCC
The recommended command is:

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

Msvc
The recommended build command is:

nmake -f makefile.vc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1

This process takes a long time. A fast machine can be completed in about 30 minutes. It may take several hours to slow down.

If the GCC version used is newer, a large number of warnings may occur during the build process. This will obviously cause the building process to slow down; you can redirect the error information to the file and add2> err.log
, You can also use2>nul
Directly disable warning information.

For more information about the build, shared, monolithic, and Unicode options, see the solution of wxWidgets's building parameters.
These parameters are critical. They directly define the basic wxWidgets development environment you are using. You must set the code: blocks configuration to strictly follow your compilation Parameters
Import.

Create a wxWidgets project in code: Blocks

On the code: blocks start page, select "Create a new project", or select "new"-> "project…" from the File menu ...".

Find and select "wxWidgets project" and create the project. A wizard is displayed to help configure the wxWidgets project:

  1. The first page is the introduction. You can skip it later.
  2. Select the wxWidgets version you want to use. If you configure it according to the process described in this article, you should select "wxWidgets 2.8.x ".
  3. Set the location of your project name.
  4. Enter the author's information (not required)
  5. Select Automatic Code and file generation options.
  6. Select the location of wxWidgets. We strongly recommend that you use global variables here: Enter "$ (# wx)" (excluding quotation marks ). If you have not defined this global variable, the global variable dialog box appears. In the base path, select your wxWidgets installation path. Other paths are optional.
  7. Select debug/release configuration for your project. We recommend that you select at least debug configuration.
  8. Select your wxWidgets build option. It must be consistent with the option used when you build wxWidgets! If you follow the method previously described in this article
    "WxWidgets Library
    Select all three options under settings. If wxpack is used, because wxpack contains different versions, you only need to select the options you need. Another
    One setting has nothing to do with the wxWidgets build options. You can choose one as you like. If, for some reason, you want to use the wxWidgets build of the debug version, select
    "Configure advanced options" and then select "use _ wxdebug _ and debug" on the next page
    WxWidgets lib ".
  9. Select an additional library if needed. Generally, you do not need to select either of them.
Build and run the program

Next, you can select "build and run" (F9) to build and run the program. If it succeeds, your wxWidgets application will appear. If any problem occurs, you can refer to the following Frequently asked questions.

WxWidgets compilation option overview build

Build control wxWidgets build debugging version (build = Debug) or release version (build = release ). In most cases, you only need
You can release wxWidgets, because you do not want to debug wxWidgets itself, and you can still build your own by linking the released version of wxWidgets.
The debugging version of your program.

  • Debugging
    Building wxWidgets will create a library with the suffix "D", such as "libwxmsw28d. A" and "wxmsw28d_gcc_custom.dll ".
  • Debugging
    When wxWidgets is built, the "mswd" or "mswud" Directory will be created in the output directory of the wxWidgets library.
  • Release
    The library created by building wxWidgets does not have the "D" suffix, for example, "libwxmsw28.a" and "wxmsw28_gcc_custom.dll ".
  • Release
    When wxWidgets is built, the "MSW" or "mswu" directory is created in the output directory of the wxWidgets library.
Shared

Shared controls whether wxWidgets constructs a DLL (shared = 1) or a static library (shared = 0 ). Using the constructed DLL, the main program can be built quickly, and the executable files are smaller. However, the total size of the executable file with wxWidgets DLL is larger, but the same dll can be used for different executable files.

  • WxWidgetsDLL
    The build will create a imported Library (such as libwxmsw28.a) and a DLL file (such as wxmsw28_gcc_custom.dll ). You must include this DLL when releasing your program.
  • WxWidgetsStatic
    The build only creates a static library (such as libwxmsw28.a), and does not need to include wxWidgets DLL during release.
Monolithic

Monolithic controls whether to build a single library (monolithic = 1) or Multiple Component Libraries (monolithic = 0 ). Use Single build and Project Settings
And development will be simpler. If you build with DLL at the same time, you only need to distribute a DLL file. If you use a non-single build (multilib), multiple different libraries will be built and you can
To avoid linking the basic wxWidgets code to the main program, you can remove unnecessary libraries. Make sure that you have selected the correct component library.

  • WxWidgetsSingle
    Only one wxWidgets import library (such as libwxmsw28.a) and one DLL (such as wxmsw28_gcc_custom.dll) will be created for the build ).
  • WxWidgetsMultiple databases
    (Multilib) the build creates multiple import/export libraries (libwx28_base.a) and multiple DLL files.
  • Any wxWidgets build will create additionalStatic
    Library (such as libwxexpat. A and libwxjpeg. ). These libraries are generally not required for wxWidgets DLL build, but are required when static build is used.
Unicode

Unicode controls wxWidgets and whether your program uses a wide string that supports Unicode. Most applications on Windows 2000 or higher should support Unicode. Earlier Windows versions do not necessarily support Unicode. You should always use wxWidgets_("string")
And_T("string")
Macro to ensure that hard-coded strings are of the correct type during compilation.

  • WxWidgetsUnicode
    (UNICODE = 1) the build will create a library with the "U" suffix, such as "libwxmsw28u. A" and "wxmsw28u_gcc_custom.dll ".
  • WxWidgetsUnicode
    The "mswu" or "mswud" Directory will be created in the output directory of the wxWidgets library.
  • WxWidgetsANSI
    (UNICODE = 0) The created library does not have the "U" suffix, for example, "libwxmsw28.a" or "wxmsw28_gcc_custom.dll ".
  • WxWidgetsANSI
    The "MSW" or "mswd" Directory will be created in the output directory of the wxWidgets library.
A common error similar to "wx/setup. h: no such file or directory" occurs.

You lack an important compiler search path in the build options. First, check whether you have correctly selected the wxWidgets build configuration when running the wxWidgets Project Wizard. If you re-run the wizard and the configuration is still invalid, open the build option of your project and add it to the compiled search path"$(#wx.lib)/gcc_dll/mswu
"(Here we assume a single Unicode DLL
Build ).

Error similar to "cannot find-lwxmsw28u"

The Link Library in the build option is incorrect. First, check whether you have correctly selected the wxWidgets build configuration when running the wxWidgets Project Wizard. If the Wizard is re-run and the configuration is still invalid, determine the database you have built and adjust the database name in the build options accordingly.

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.