Difference between revisions of "WxWindowsQuickRef"

From Code::Blocks
(Added supported compilers notation, removed self-credit)
m (Added comment to indicate where the resulting DLLs can be found.)
 
(20 intermediate revisions by 8 users not shown)
Line 7: Line 7:
  
 
'''Important Requirements:'''
 
'''Important Requirements:'''
* '''Windows compiler''' - You need to have correctly installed the free [http://www.mingw.org/ MinGW/GCC] compiler or one of [http://msdn.microsoft.com/vstudio/ Microsoft's compilers] (the [http://msdn.microsoft.com/vstudio/express/ Express editions] are free, but you must also install the [http://www.microsoft.com/downloads/details.aspx?familyid=0baf2b35-c656-4969-ace8-e4c0c0716adb Platform SDK]). If using MinGW/GCC, you need at least the gcc-core, gcc-g++, binutils, w32api, and mingw32-make packages; also, ensure that the folder containing the compiler executables (typically C:\MinGW\bin) is in your [http://vlaurie.com/computers2/Articles/environment.htm#editing Windows PATH environment variable].
+
* '''Recent version of Code::Blocks''' - You need to have successfully installed and run a recent version of Code::Blocks -- either [https://www.codeblocks.org/downloads/26 the 17.12 release] or [/index.php/board,20.0.html a recent nightly build].
* '''Recent version of Code::Blocks''' - You need to have successfully installed and run a recent version of Code::Blocks -- either [https://www.codeblocks.org/downloads/5 the 8.02 release] or [/index.php/board,20.0.html a recent nightly build].
 
  
 +
* '''Windows compiler''' - You need to have correctly installed either
 +
**the [http://www.mingw.org/ MinGW/GCC] free compiler (or one of its forks), or
 +
**[http://msdn.microsoft.com/vstudio/ Microsoft Visual C++] (the [http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products Express editions] are free, but you must also install the [http://www.microsoft.com/en-us/download/details.aspx?id=8279 Platform SDK]).
 +
When downloading an official Code::Blocks release, you have the option of downloading a bundle package that includes a full MinGW/GCC toolchain.
  
== Download wxWidgets ==
+
* '''Path properly defined''' - Ensure that the folder containing the compiler executables (typically C:\Program Files\CodeBlocks\bin, or C:\MinGW32\bin) is in your [http://vlaurie.com/computers2/Articles/environment.htm#editing Windows PATH environment variable].
You can choose to download the wxWidgets source code and compile it yourself, or download the "wxPack", a precompiled version.
 
* '''The wxWidgets sources''' are a much smaller download, but you must also spend some time compiling them.
 
* '''wxPack''' is a much larger download, but you don't have to spend time compiling it or worry about build options.
 
  
=== wxWidgets Sources ===
 
The current recommended version of wxWidgets to use is '''2.8.8'''. [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.8-Setup.exe Click here to download the wxWidgets 2.8.8 sources for Windows] (wxMSW-2.8.8-Setup.exe; 12.0 MB). You can check [http://www.wxwidgets.org/downloads/ the wxWidgets download page] to see if a newer stable version is available. '''It is highly recommended that you install the sources to a path without spaces.''' You should choose a volume with at least 300 MB of free space.
 
  
=== wxPack ===
+
== Download wxWidgets Source Code ==
The current stable release of wxPack is '''v2.8.7.03''', based on wxWidgets 2.8.7. [http://downloads.sourceforge.net/wxpack/wxPack_v2.8.7.03.exe?download Click here to download wxPack v2.8.7.03] (wxPack_v2.8.7.03.exe, 236.9 MB). You can check [http://wxpack.sourceforge.net/Main/Downloads the wxPack download page] to see if a newer stable version is available. '''It is highly recommended that you install wxPack in a path without spaces.''' You should choose a volume with at least 700 MB of free space for MSVC, or 2.2 GB of free space for MinGW/GCC.
+
wxWidgets is distributed in source code format, and you need to compile it into a library before you can use it in your own programs.
 +
 
 +
The current recommended version of wxWidgets to use is '''2.8.12'''. [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.12-Setup.exe Click here to download the wxWidgets 2.8.12 sources for Windows] (wxMSW-2.8.12-Setup.exe; 12.2 MB). You can check [http://www.wxwidgets.org/downloads/ the wxWidgets download page] to see if a newer stable version is available. '''It is highly recommended that you install the sources to a path without spaces.''' You should choose a volume with at least 300 MB of free space.
 +
 
 +
'' '''wxPack''' is no longer recommended for use, as it is built with a much older version of GCC.''
 +
 
  
 
== Build wxWidgets ==
 
== Build wxWidgets ==
''This step is unnecessary if you are using '''wxPack''' ''
 
 
 
* Open up a command prompt for building. If you are using MinGW/GCC, simply use the standard Windows command shell (open the Start menu, click "Run...", enter "cmd" and hit OK). If you are using MSVC, you should use the special command shell which sets up the correct environment variables for you. If you use a version of MSVC which required you to download the Platform SDK separately, ensure that whichever command environment you use includes the Platform SDK tools and paths as well as the standard compiler tools and paths.
 
* Open up a command prompt for building. If you are using MinGW/GCC, simply use the standard Windows command shell (open the Start menu, click "Run...", enter "cmd" and hit OK). If you are using MSVC, you should use the special command shell which sets up the correct environment variables for you. If you use a version of MSVC which required you to download the Platform SDK separately, ensure that whichever command environment you use includes the Platform SDK tools and paths as well as the standard compiler tools and paths.
* Change to the wxWidgets build directory (where <wxWidgets> is the path you extracted the sources to; typically C:\wxWidgets-2.8.8):
+
* Change to the wxWidgets build directory (where <wxWidgets> is the path you extracted the sources to; typically C:\wxWidgets-2.8.12):
  cd <wxWidgets>\build\msw
+
  cd /D <wxWidgets>\build\msw
 +
''Note: the <code>/D</code> flag after <code>cd</code> may be omitted from the command; it simply allows command prompt to change drives if necessary.
 
* Execute the build command. The recommended command to use for '''MinGW/GCC''' is:
 
* Execute the build command. The recommended command to use for '''MinGW/GCC''' is:
  mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
+
  mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-fno-keep-inline-dllexport
 
* The recommended command to use for '''MSVC''' is:
 
* The recommended command to use for '''MSVC''' is:
 
  nmake -f makefile.vc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
 
  nmake -f makefile.vc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
 
* This step will generally take a long time; faster PCs may expect 30-minute build times, and slower PCs can take as much as several hours.
 
* This step will generally take a long time; faster PCs may expect 30-minute build times, and slower PCs can take as much as several hours.
 
* If using more recent versions of GCC, many warnings will occur during the build. This can slow the build process noticeably; you may want to redirect the warnings to a text file by appending "2>errlog.txt" to the build command, or supress them entirely by appending "2>nul".
 
* If using more recent versions of GCC, many warnings will occur during the build. This can slow the build process noticeably; you may want to redirect the warnings to a text file by appending "2>errlog.txt" to the build command, or supress them entirely by appending "2>nul".
 +
* If the build is successful, gcc dlls will be placed at ../lib/gcc_dll/wxmsw<version>_gcc_custom.dll
 +
 +
The "CXXFLAGS=-fno-keep-inline-dllexport" option is necessary with recent versions of GCC (not with MSVC), to prevent problems with memory usage when performing the final link step on the monolithic DLL.
  
 
See the section below titled "wxWidgets build options explained" for details on the meaning of the BUILD, SHARED, MONOLITHIC, and UNICODE options. These options are critically important, because they define the basic wxWidgets development environment you will be using. You must duplicate them exactly when running Code::Blocks' wxWidgets project wizard.
 
See the section below titled "wxWidgets build options explained" for details on the meaning of the BUILD, SHARED, MONOLITHIC, and UNICODE options. These options are critically important, because they define the basic wxWidgets development environment you will be using. You must duplicate them exactly when running Code::Blocks' wxWidgets project wizard.
 +
  
 
== Create a wxWidgets project in Code::Blocks ==
 
== Create a wxWidgets project in Code::Blocks ==
Line 44: Line 50:
 
# Set your project title and location.
 
# Set your project title and location.
 
# Enter author details if you wish (not required).
 
# Enter author details if you wish (not required).
 +
# ''At this point wiki member WardXmodem's gives a "select your GUI options" - can someone detail their meanings?''
 
# Select options for automatic code and file generation.
 
# Select options for automatic code and file generation.
 
# Select wxWidgets' location. It's highly recommended that you use a global variable for this: enter "$(#wx)" (without quotes). If you haven't already defined this global variable, the global variables dialog will appear; for the base path, select your wxWidgets installation location. You don't need to fill in the other paths.
 
# Select wxWidgets' location. It's highly recommended that you use a global variable for this: enter "$(#wx)" (without quotes). If you haven't already defined this global variable, the global variables dialog will appear; for the base path, select your wxWidgets installation location. You don't need to fill in the other paths.
 
# Select debug and/or release configurations for your project. The debug configuration at least is recommended.
 
# Select debug and/or release configurations for your project. The debug configuration at least is recommended.
# Choose your wxWidgets build options. '''These must match the options used when you built wxWidgets!''' If you followed the directions above, select all three of the options under "wxWidgets Library Settings". '''If you are using wxPack:''' wxPack includes each version, so you may select whichever options you prefer. The other settings on this page are not related to the wxWidgets build options; you may use them or not as you prefer. In order to avoid using a debug wxWidgets build (as recommended), you must select "Configure Advanced options" and then leave "Use __WXDEBUG__ and Debug wxWidgets lib" unchecked on the next page.
+
# Choose your wxWidgets build options. '''These must match the options used when you built wxWidgets!''' If you followed the directions above, select all three of the options under "wxWidgets Library Settings". The other settings on this page are not related to the wxWidgets build options; you may use them or not as you prefer. In order to avoid using a debug wxWidgets build (as recommended), you must select "Configure Advanced options" and then leave "Use __WXDEBUG__ and Debug wxWidgets lib" unchecked on the next page.
 
# Select additional libraries if required. You should not need to select any of these for normal usage.
 
# Select additional libraries if required. You should not need to select any of these for normal usage.
  
Line 71: Line 78:
 
=== MONOLITHIC ===
 
=== MONOLITHIC ===
 
MONOLITHIC controls whether a single library (MONOLITHIC=1) or multiple component libraries (MONOLITHIC=0) are built. With a monolithic build, project setup and development are much easier, and you only have one DLL to distribute if you're using a DLL build. With a non-monolithic (multilib) build, several different libraries are built and you can avoid linking with the entire wxWidgets codebase for programs that don't need it. You do have to ensure that you choose the correct component libraries.
 
MONOLITHIC controls whether a single library (MONOLITHIC=1) or multiple component libraries (MONOLITHIC=0) are built. With a monolithic build, project setup and development are much easier, and you only have one DLL to distribute if you're using a DLL build. With a non-monolithic (multilib) build, several different libraries are built and you can avoid linking with the entire wxWidgets codebase for programs that don't need it. You do have to ensure that you choose the correct component libraries.
* A '''monolithic''' build of wxWidgets creates a single wxWidgets import library (such as libwxmsw28.a) and a single DLL (such as wxmsw28_gcc_custom.dll).
+
* A '''monolithic''' build of wxWidgets creates a single wxWidgets import library (such as libwxmsw28u.a) and a single DLL (such as wxmsw28_gcc_custom.dll).
* A '''multilib''' build of wxWidgets creates multiple import libraries (libwx28_base.a, etc.) and multiple DLLs.
+
* A '''multilib''' build of wxWidgets creates multiple import libraries (libwxbase28u.a, etc.) and multiple DLLs.
 
* Additional '''static''' libraries are always created with any wxWidgets build (libwxexpat.a, libwxjpeg.a, etc.). These libraries do not normally need to be used with DLL builds of wxWidgets, but they are required when using static builds.
 
* Additional '''static''' libraries are always created with any wxWidgets build (libwxexpat.a, libwxjpeg.a, etc.). These libraries do not normally need to be used with DLL builds of wxWidgets, but they are required when using static builds.
  
Line 87: Line 94:
 
'''I get errors like "wx/setup.h: No such file or directory"'''
 
'''I get errors like "wx/setup.h: No such file or directory"'''
  
You're missing an important compiler search path in your build options. Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard. If re-running the wizard isn't an option, then open your project's build options and add "$(#wx.lib)\gcc_dll\mswu" (assuming a <u>monolithic Unicode DLL</u> build) to the compiler search paths.
+
You're missing an important compiler search path in your build options. Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard. If re-running the wizard isn't an option, then open your project's build options and add "$(#wx.lib)\gcc_dll\mswu" (assuming a <u>monolithic Unicode DLL</u> build) or "$(#wx.lib)\gcc_lib\mswu" (assuming a <u>multilib Unicode </u> build)to the compiler search paths.
  
 
'''I get errors like "cannot find -lwxmsw28u"'''
 
'''I get errors like "cannot find -lwxmsw28u"'''
  
 
You have an incorrect link library in your build options. Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard. If re-running the wizard isn't an option, determine which version of the library is built and adjust the library name in your build options accordingly.
 
You have an incorrect link library in your build options. Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard. If re-running the wizard isn't an option, determine which version of the library is built and adjust the library name in your build options accordingly.
 +
 +
'''I get errors like "undefined reference to _Unwind_*"'''
 +
 +
wxWidgets was built with a different version of GCC than the one you're currently using. You need to rebuild wxWidgets with the same version of GCC that you use to compile your program.
 +
 +
==See also==
 +
Forum thread - [/index.php?topic=5359.0 Newbie problem in setting up wxwidgets and Codeblocks]

Latest revision as of 18:26, 17 March 2021

A beginner's quick reference for setting up wxWidgets with Code::Blocks in Windows
Supported compilers: MinGW or MSVC

Chinese Translation


Important Requirements:

  • Recent version of Code::Blocks - You need to have successfully installed and run a recent version of Code::Blocks -- either the 17.12 release or [/index.php/board,20.0.html a recent nightly build].

When downloading an official Code::Blocks release, you have the option of downloading a bundle package that includes a full MinGW/GCC toolchain.

  • Path properly defined - Ensure that the folder containing the compiler executables (typically C:\Program Files\CodeBlocks\bin, or C:\MinGW32\bin) is in your Windows PATH environment variable.


Download wxWidgets Source Code

wxWidgets is distributed in source code format, and you need to compile it into a library before you can use it in your own programs.

The current recommended version of wxWidgets to use is 2.8.12. Click here to download the wxWidgets 2.8.12 sources for Windows (wxMSW-2.8.12-Setup.exe; 12.2 MB). You can check the wxWidgets download page to see if a newer stable version is available. It is highly recommended that you install the sources to a path without spaces. You should choose a volume with at least 300 MB of free space.

wxPack is no longer recommended for use, as it is built with a much older version of GCC.


Build wxWidgets

  • Open up a command prompt for building. If you are using MinGW/GCC, simply use the standard Windows command shell (open the Start menu, click "Run...", enter "cmd" and hit OK). If you are using MSVC, you should use the special command shell which sets up the correct environment variables for you. If you use a version of MSVC which required you to download the Platform SDK separately, ensure that whichever command environment you use includes the Platform SDK tools and paths as well as the standard compiler tools and paths.
  • Change to the wxWidgets build directory (where <wxWidgets> is the path you extracted the sources to; typically C:\wxWidgets-2.8.12):
cd /D <wxWidgets>\build\msw

Note: the /D flag after cd may be omitted from the command; it simply allows command prompt to change drives if necessary.

  • Execute the build command. The recommended command to use for MinGW/GCC is:
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 CXXFLAGS=-fno-keep-inline-dllexport
  • The recommended command to use for MSVC is:
nmake -f makefile.vc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
  • This step will generally take a long time; faster PCs may expect 30-minute build times, and slower PCs can take as much as several hours.
  • If using more recent versions of GCC, many warnings will occur during the build. This can slow the build process noticeably; you may want to redirect the warnings to a text file by appending "2>errlog.txt" to the build command, or supress them entirely by appending "2>nul".
  • If the build is successful, gcc dlls will be placed at ../lib/gcc_dll/wxmsw<version>_gcc_custom.dll

The "CXXFLAGS=-fno-keep-inline-dllexport" option is necessary with recent versions of GCC (not with MSVC), to prevent problems with memory usage when performing the final link step on the monolithic DLL.

See the section below titled "wxWidgets build options explained" for details on the meaning of the BUILD, SHARED, MONOLITHIC, and UNICODE options. These options are critically important, because they define the basic wxWidgets development environment you will be using. You must duplicate them exactly when running Code::Blocks' wxWidgets project wizard.


Create a wxWidgets project in Code::Blocks

  • On the Code::Blocks Start Page, select "Create a new project"; alternatively, open the File menu, highlight "New" and select "Project..."
  • Select "wxWidgets project"
  1. The first page is an introduction, which you can choose to skip in the future.
  2. Select which version of wxWidgets you will be using. If you followed the instructions above, you should select "wxWidgets 2.8.x".
  3. Set your project title and location.
  4. Enter author details if you wish (not required).
  5. At this point wiki member WardXmodem's gives a "select your GUI options" - can someone detail their meanings?
  6. Select options for automatic code and file generation.
  7. Select wxWidgets' location. It's highly recommended that you use a global variable for this: enter "$(#wx)" (without quotes). If you haven't already defined this global variable, the global variables dialog will appear; for the base path, select your wxWidgets installation location. You don't need to fill in the other paths.
  8. Select debug and/or release configurations for your project. The debug configuration at least is recommended.
  9. Choose your wxWidgets build options. These must match the options used when you built wxWidgets! If you followed the directions above, select all three of the options under "wxWidgets Library Settings". The other settings on this page are not related to the wxWidgets build options; you may use them or not as you prefer. In order to avoid using a debug wxWidgets build (as recommended), you must select "Configure Advanced options" and then leave "Use __WXDEBUG__ and Debug wxWidgets lib" unchecked on the next page.
  10. Select additional libraries if required. You should not need to select any of these for normal usage.

Build and Run

Select "Build and run" (F9) to, well, build and run. If all goes well, your wxWidgets basic program should appear.


wxWidgets Build Options Explained

What do the BUILD, SHARED, MONOLITHIC, and UNICODE options mean?

BUILD

BUILD controls whether a debug version (BUILD=debug) or release version (BUILD=release) of wxWidgets itself is built. In the vast majority of cases you will only need a release version of wxWidgets, since you won't be interesting in debugging wxWidgets itself. You can still create debug builds of your own programs that link to a release build of wxWidgets.

  • A debug build of wxWidgets creates libraries with a "d" suffix -- for example, "libwxmsw28d.a"/"wxmsw28d_gcc_custom.dll".
  • A debug build of wxWidgets creates the folder "mswd" or "mswud" in the wxWidgets library output folder.
  • A release build of wxWidgets creates libraries without the "d" suffix -- for example, "libwxmsw28.a"/"wxmsw28_gcc_custom.dll".
  • A release build of wxWidgets creates the folder "msw" or "mswu" in the wxWidgets library output folder.

SHARED

SHARED controls whether a DLL (SHARED=1) or static (SHARED=0) version of wxWidgets is built. With a DLL build, compile times are faster and the executable size is smaller. The total size of a single executable plus the wxWidgets DLL is greater, but multiple executables can use the same DLL.

  • A DLL build of wxWidgets creates import libraries (such as libwxmsw28.a) and DLLs (such as wxmsw28_gcc_custom.dll). You must include the DLL when you distribute your program.
  • A static build of wxWidgets creates static libraries only (such as libwxmsw28.a), and you do not need to distribute a wxWidgets DLL.

MONOLITHIC

MONOLITHIC controls whether a single library (MONOLITHIC=1) or multiple component libraries (MONOLITHIC=0) are built. With a monolithic build, project setup and development are much easier, and you only have one DLL to distribute if you're using a DLL build. With a non-monolithic (multilib) build, several different libraries are built and you can avoid linking with the entire wxWidgets codebase for programs that don't need it. You do have to ensure that you choose the correct component libraries.

  • A monolithic build of wxWidgets creates a single wxWidgets import library (such as libwxmsw28u.a) and a single DLL (such as wxmsw28_gcc_custom.dll).
  • A multilib build of wxWidgets creates multiple import libraries (libwxbase28u.a, etc.) and multiple DLLs.
  • Additional static libraries are always created with any wxWidgets build (libwxexpat.a, libwxjpeg.a, etc.). These libraries do not normally need to be used with DLL builds of wxWidgets, but they are required when using static builds.

UNICODE

UNICODE controls whether wxWidgets and your program use wide-character strings with Unicode support. Most programs for Windows 2000 and later should do so. Earlier versions of Windows don't have the necessary Unicode support. You should always use wxWidget's _("string") and _T("string") macros to ensure that your hardcoded strings are the correct type.

  • A Unicode (UNICODE=1) build of wxWidgets creates libraries with a "u" suffix -- for example, "libwxmsw28u.a"/"wxmsw28u_gcc_custom.dll".
  • A Unicode build of wxWidgets creates the folder "mswu" or "mswud" in the wxWidgets library output folder.
  • An ANSI (UNICODE=0) build of wxWidgets creates libraries without the "u" suffix -- for example, "libwxmsw28.a"/"wxmsw28_gcc_custom.dll".
  • An ANSI build of wxWidgets creates the folder "msw" or "mswd" in the wxWidgets library output folder.


Frequently Asked Questions

I get errors like "wx/setup.h: No such file or directory"

You're missing an important compiler search path in your build options. Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard. If re-running the wizard isn't an option, then open your project's build options and add "$(#wx.lib)\gcc_dll\mswu" (assuming a monolithic Unicode DLL build) or "$(#wx.lib)\gcc_lib\mswu" (assuming a multilib Unicode build)to the compiler search paths.

I get errors like "cannot find -lwxmsw28u"

You have an incorrect link library in your build options. Make sure you choose the correct wxWidgets build configuration when running the wxWidgets project wizard. If re-running the wizard isn't an option, determine which version of the library is built and adjust the library name in your build options accordingly.

I get errors like "undefined reference to _Unwind_*"

wxWidgets was built with a different version of GCC than the one you're currently using. You need to rebuild wxWidgets with the same version of GCC that you use to compile your program.

See also

Forum thread - [/index.php?topic=5359.0 Newbie problem in setting up wxwidgets and Codeblocks]