Compiling WxWidgets
From WxWiki
Contents |
[edit] Installation instructions
Your main guide for compiling wxWidgets should be the installation instructions.
For all architectures: Look for the file 'install.txt'! - It contains important and useful information. It's in the archive in <code>/docs/your-arch/install.txt</code>.
- Compiling A WxWidgets Application - settings for various compilers: g++ and MSVC
[edit] Compiling on Windows
- Choosing Which Compiler To Use
- Compiling WxWidgets With MSYS-MinGW
- Installing WxWin - How to get started on wxWidgets for Microsoft Windows with VC++ 6.0.
- Installing WxWin For MS Free Tools - How to get started on wxWidgets with thefree MS Tools.
- MS Free Tools And WxWidgets - How to get with the free tools from microsoft to compile wxMSW-2.6.0.zip.
- Installing WxWin Watcom - Howto with Open Watcom (free C++ compiler from http://www.openwatcom.org)
- Cygwin
- Installing WxWin MinGW - How to use MinGW in combination with Eclipse.
- User's Guide For VC++ 6.0 - How to set up wxWidgets for use with Visual C++ 6.0
- A guide to using MinGW and Eclipse with wxWidgets on Windows: http://howtos.mrcam.org/guides/development/cppguiprogramming.html
Some unix-minded people will prefer to build Windows executables by Cross-Compiling Under Linux
[edit] Microsoft Visual C++ 6.0 (on the command-line)
You can also compile wxWidgets using only the command-line interface to Visual C++ 6.0. See Compiling Using MSVC On The Commandline. This is particularly useful for people wanting to compile source from CVS. The command line compiler is now available free from Microsoft as Microsoft Visual C++ Toolkit 2003.
[edit] Microsoft Visual Studio
[edit] Static Compilation
Follow the proceeding instructions if you wish to compile the wxWidgets library, sample applications, or your own applications built on top of wxWidgets, in Visual C++ 2005. This will perform static compilation, creating an .exe application that will run on any Windows platform with no dependencies that need to be supplied by the developer. The instructions have been verified with wxWidgets 2.6.2, and versions 8.0 of both listed compilers.
[edit] Microsoft Visual C++ 2005 Express Edition
Alas, compiling wxWidgets with the Express Edition is different from the Standard editions. Why? I have no idea, but it is frustrating.
One key thing to note: The Express Edition does not come with the Win32 Platform SDK!!! This means, you have to download it separately. [1], or do a Google search for Windows SDK. It will be the first link. If you are getting errors about "windows.h cannot be found", the compiler is not pointed to the correct Platform SDK location.
Download the Express Edition and install it. Download the Platform SDK as shown above. You will have to make sure your projects are set to point to the SDK. Tools -> Options -> Projects and Solutions -> VC++ Directories. Use the "Show Directories For" pulldown menu, and make sure the Include and Library pulldowns have the correct Platform SDK directories. You can now begin the compilation of wxWidgets.
[edit] wxWidgets Library
Follow the exact same instructions as with VC++ 2005 Standard/Professional Edition
- Hint: if you receive the linker error "missing odbc32.lib", you may need to install the Data Access components for Visual Studio.
[edit] Sample Projects
1-3). Follow the exact same instructions as with VC++ 2005 Standard/Professional Edition. 4). For both Debug and Release, you will need to add the following libraries to the beginning of your "Additional Dependencies".
comctl32.lib rpcrt4.lib shell32.lib gdi32.lib kernel32.lib user32.lib comdlg32.lib ole32.lib oleaut32.lib advapi32.lib
[edit] Your Application
- For both Debug/Release, follow the exact same instructions as with VC++ 2005 Standard/Professional Edition. - REMOVE odbc32.lib from both Debug/Release builds. - For both Debug and Release, you will need to add the following libraries to the beginning of your "Additional Dependencies".
comctl32.lib rpcrt4.lib shell32.lib gdi32.lib kernel32.lib
user32.lib comdlg32.lib ole32.lib oleaut32.lib advapi32.lib
[edit] Microsoft Visual C++ 2005 Standard/Professional Edition
[edit] wxWidgets Library
1). Download wxWidgets.exe (The .exe will set the environment variable WXWIN). Or you can download the .zip, but you will either have to manually add your environment variables, or type in the paths manually for includes and libs. 2). Compile wxWidgets.
- Open build\msw\wx.dsw
- Convert all projects (Yes to All).
- If you want to link against the static runtime libraries you should
- For each project, right click, click Properties. Configuration Properties -> C/C++ -> Code Generation
- For Debug, change Run Time Library to Multi-Threaded Debug (/MTd)
- For Release, change Runtime Library to Multi-Threaded (/MT)
Shortcut:
You can accomplish the same effect if you open .vcproj file(s)
in text editor and replace the following strings
- RuntimeLibrary="3" with RuntimeLibrary="1"
- RuntimeLibrary="2" with RuntimeLibrary="0"
If you have an editor which can do the replacement across all opened files (as Notepad++), the job is much easier.
Note: Most usually you don't want to do this (link against the static runtime libraries, that is).
- Batch build: Select all "Debug" and "Release" builds (not dll or unicode)
- Build all projects.
(Any other libs you want to compile (such as in contrib) will follow the same process).
[edit] Sample Projects
(With the above configuration)
1). If you want to link against the static runtime libraries you should:
For each project, right click, click Properties. Configuration Properties -> C/C++ -> Code Generation
- For Debug, change Run Time Library to Multi-Threaded Debug (/MTd)
- For Release, change Runtime Library to Multi-Threaded (/MT)
Shortcut:
You can accomplish the same effect if you open .vcproj file(s)
in text editor and replace the following strings
- RuntimeLibrary="3" with RuntimeLibrary="1"
- RuntimeLibrary="2" with RuntimeLibrary="0"
If you have an editor which can do the replacement across all opened files (as Notepad++), the job is much easier.
2). If project uses a resource (.rc), add the line: #define wxUSE_NO_MANIFEST 1
- i.e. the 'text' sample .rc file will look like this:
mondrian ICON "mondrian.ico"
#define wxUSE_NO_MANIFEST 1
#include "wx/msw/wx.rc"
3). Build Debug or Release versions (not dll)
[edit] Your Application
[edit] DEBUG
Noteworthy settings (different from default .NET 2005 project)
- Configuration Properties:
- General:
- Character Set: Not Set (Unless you need Unicode support. My app doesn't need Unicode, so this setting lets me avoid prefixing my strings w/ Unicode macros).
- General:
- C/C++:
- General:
- Additional Include Directories: $(WXWIN)\include;$(WXWIN)\contrib\include;$(WXWIN)\lib\vc_lib\mswd (This will be different if you didn't install with the .exe and didn't set environment variables).
- Preprocessor:
- Preprocessor Definitions: WIN32;_DEBUG;__WXMSW__;__WXDEBUG__;_WINDOWS;NOPCH;_CRT_NONSTDC_NO_DEPRECATE (This last one eliminates many warning messages)
- Code Generation:
- Runtime Library: Multi-Threaded Debug DLL (/MDd)
- Linker:
- General:
- Additional Library Directories: "$(WXWIN)\lib";"$(WXWIN)\contrib\lib";"$(WXWIN)\lib\vc_lib"
- (The above will be different if you didn't install with the .exe and didn't set environment variables).
- General:
- Input:
- Additional Dependencies: wxmsw28d_core.lib wxbase28d.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexd.lib wxexpatd.lib winmm.lib comctl32.lib rpcrt4.lib wsock32.lib oleacc.lib
- Manifest File:
- Generate Manifest: No
- General:
- To get your resources working properly, you need to create a .rc file.
- Create a new text file, with a .rc extension. Include this to your project. The text file should contain the line:
#include <wx/msw/wx.rc>
- Right click the resource and set the Additional Includes to the same as above.
------RELEASE------
- Noteworthy settings (different from default .NET 2005 project)
Configuration Properties:
General:
- Character Set: Not Set (Unless you need Unicode support. My app doesn't need Unicode, so this setting
lets me avoid prefixing my strings w/ Unicode macros).
C/C++:
General:
- Additional Include Directories: $(WXWIN)\include;$(WXWIN)\contrib\include;$(WXWIN)\lib\vc_lib\msw
- (The above will be different if you didn't install with the .exe and didn't set environment variables).
Preprocessor:
- Preprocessor Definitions: WIN32;__WXMSW__;_WINDOWS;NOPCH;_CRT_NONSTDC_NO_DEPRECATE
(This last one eliminates many warning messages)
Code Generation:
- Runtime Library: Multi-Threaded DLL (/MD)
Linker:
General:
- Additional Library Directories: "$(WXWIN)\lib";"$(WXWIN)\contrib\lib";"$(WXWIN)\lib\vc_lib"
- (The above will be different if you didn't install with the .exe and didn't set environment variables).
Input:
- Additional Dependencies: wxmsw28_core.lib wxbase28.lib wxtiff.lib
wxjpeg.lib wxpng.lib wxzlib.lib wxregex.lib
wxexpat.lib winmm.lib comctl32.lib rpcrt4.lib
wsock32.lib oleacc.lib odbc32.lib
Manifest File:
- Generate Manifest: No
- To get your resources working properly, you need to create a .rc file.
- Create a new text file, with a .rc extension. Include this to your project. The text file should contain the line:
#include <wx/msw/wx.rc>
- Right click the resource and set the Additional Includes to the same as above.
[edit] Additional Notes
In WxWidgets 2.6.3, wxregex.lib and wxregexd.lib seem to have been renamed to regex.lib and regexd.lib - update appropriate linkage in instructions above if you are using this version.
You need to go into the 'src' directory and use open wxWidgets.dsw (not wxWidgets.dsp or wxBase, unless you're certain that's what you want)
Before compiling, you might want to alter the defaults in <code>include\wx\msw\setup.h</code> to enable or disable threads support, i18n support, socket support, opengl support, etcetera. Also at some later point, when more setup.h's have been generated, this is the one to edit. See Setup.h
Also, if you're compiling wxWidgets to use in a specific one of the projects that use wxWidgets, do READ that project's instructions too. Sometimes you may need to change the default options a little, (e.g. to build statically linked libraries rather than DLLs) to get options to match what you need to work with that project.
If you have errors like:
MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgheap.obj)
, then put this in Linker > Input > "Ignore Specific Library" : LIBCMTD in debug or LIBCMT in release.
[edit] Compiling Contrib
If you want to build the contrib samples then you may have to add the appropriate contrib library to the linker input files (this is certainly true for the VC++ project files up to 2.3.4). Otherwise you may get errors like (for VC++):
tree.obj : error LNK2001: unresolved external symbol
"public: __thiscall wxTreeCompanionWindow::wxTreeCompanionWindowclass wxWindow *,int,class wxPoint const &,class wxSize const &,long)"
Then if you get errors regarding duplicate symbols such as
gizmos.lib(splittree.obj) : error LNK2005:
"public: __thiscall wxString::~wxString(void)" (??1wxString@@QAE@XZ) already defined in wxmsw233.lib(wxmsw233.dll)
try setting WXUSINGDLL in the compiler preprocessor flags for the contrib library. Up to 2.3.4 (and maybe later) the contrib samples have DLL versions but some of the contrib libraries (e.g. gizmos) only have static versions.
[edit] Compiling on Linux
Reminder: If when compiling from source you decide you'd like to recompile with a different set of options, or stop the build in order to change some of the options you've selected, you must first run `make distclean` (`make clean` only removes object files) in order to remove generated configuration files before you run the configure script again with your new options. If you accidentally stop the build (by hitting ctrl-c or something) and do not wish to change any of the options, you can safely restart the build by simply typing the `make` command and it will continue right where it left off.
%debian if ./configure complains about not being able to find gtk-config, install the 'libgtk2.0-dev' package %%
If the compile fails with the error "had to relocate PCH", try addint "--disable-precomp-headers' to your ./configure line.
You can create windows binaries without even booting to Windows! see Cross-Compiling Under Linux.
See also this page about Build System Management.
[edit] Linux building for i386 on an x86_64 machine
You may need to build 32-bit apps on an x86_64 Linux box (Suse or RHEL WS3 which is what I have). On my box at least, the 32-bit gtk libs aren't installed, so I opted to build the plain X11 version, but the config below should work for either one.
Configure like this:
mkdir build_ia32 cd build_ia32 ../configure CC='cc -m32' CXX='g++ -m32' --x-libraries=/usr/X11R6/lib ...options... make
On RHEL WS 3, there are some missing lib symlinks in /usr/lib, e.g. no libX11.so (should be a symlink to libX11.so.X.Y). You'll have to make those manually. They should be pretty obvious config or build failures.
Also, the configure script tries to search in /usr/lib64 and /usr/X11R6/lib64; remove those from SEARCH_LIBS near the top of the configure script (not doing this would make it try to link with e.g. -lXinerama, which exists but only in the 64 bit world.)
[edit] Compiling on Mac
See Mac OS X And Xcode For Beginners
[edit] Why you need to compile the library yourself
Because wxWidgets supports so many different platforms, compilers, and compile-time options, it would just not be practical to provide precompiled libraries for every possible combination.
However, the wxPack project at sourceforge provides a prebuild configuration that may be good enough to begin with.
