Difference between revisions of "Compiling and getting started"
|Line 50:||Line 50:|
== Test installation ==
== Test installation ==
Revision as of 23:48, 13 January 2009
This is a guide to help you getiing started quickly and easily on Linux with wxWidgets built from source.
Install all necessary build tools, including g++ and autotools. (On Ubuntu, you will want to install package build-essential)
You will also need gtk+ (don't forget to install the -dev package if your distro uses them). For Ubuntu 8.04 this will be libgtk-2.0-dev.
It is recommended to use at least GTK+ 2.2.3, and some features are only available when using more recent version, like GTK+ 2.8.
Download the wxGTK source archive from http://www.wxwidgets.org/downloads/ and expand it. If you intend to use it in place (not install it in system dirs) choose a place where it can stay forever because you won't be able to move it without breaking the build.
Then, the following steps are done on the terminal.
adapt path as needed
we create a new folder to build from, this enables us to have many wxWidgets builds, for instance a debug and a release one, or a Unicode and an ANSI one, or a static and a shared one, etc.
Then you will need to call configure with something like ../configure --enable-unicodeThe options you pass to configure at this point will determine what build you get.
--enable-unicode will make a Unicode build
--with-opengl will enable OpenGL support
--disable-shared will build static libs instead of shared ones
--prefix= allows you to let wxWidgets be installed at other locations than the default /usr/local
(for a list of all possible options, write ../configure --help)
If it stops saying it can't find a package, install it (with -dev packages if any) and run configure again. When it is done without errors, you are ready to build.
When the build is done, and if no error occured, you can now install it
sudo make install
Enter your password as needed. wxWidgets will be installed in /usr/local/
On some systems it is also necesary to run sudo ldconfig at this point.
Open a terminal and type
It should be the version you just built.
If it is not:
and see if it is the one you just installed (if you did not change the default value, you installed /usr/local/bin/wx-config)
if you get something like /usr/bin/wx-config while you installed /usr/local/bin/wx-config, it means there is another version of wxWidgets installed somewhere else, probably installed by the system. You can quickly get it out the way with a hacky command like sudo mv /usr/bin/wx-config /usr/bin/wx-config-old1.
Then, to test more in depth, you can look at the samples. Open the Samples folder located at wxGTK-2.8.4/gtk-build/samples (be careful : wxGTK-2.8.4/samples contains the source code, while wxGTK-2.8.4/gtk-build/samples contains the makefiles for your system. for building samples, you wil lwant to cd into the latter, while to study the code you will want to open the former)
cd into one of the samples, and type make. You can then open the sample to see wxWidgets in action.
Building apps with wxWidgets
The tool wx-config allows you to quickly build wxWidgets apps
g++ `wx-config --cppflags` `wx-config --libs` widgetTest.cpp
wx-config --cppflags returns flags necessary to compilation, wx-config --libs returns flags necessary to linking. This little example has a single file so both are used at the same time but in a bigger project compiling and linking will most likely be two different steps. (How to use g++ is beyong the scope of this document)
Running wxWidgets projects
If when running a wxWidgets app you get an error like:
./a.out: error while loading shared libraries: libwx_gtk2_aui-2.8.so.0: cannot open shared object file: No such file or directory
this means your system does not search for libs in /usr/local/libs (or wherever you installed wxWidgets) by default. To solve this, any of the following should work :
- Write 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib' on the terminal before opening the executable (from the same terminal).
- Give a --rpath /usr/local/lib/ flag to gcc while building.
- Become root and execute /sbin/ldconfig /usr/local/lib. This will configure dynamic linker run time bindings, adding the libraries on /usr/local/lib