WindowsMicrosoft Visual Studio

team bbl


Before covering the step-by-step directions for creating wxWidgets projects with Visual Studio, it should be noted that there are alternatives for generating Visual Studio project files using third-party tools. Although not covered here, utilities like DialogBlocks, wxHatch, wxWinWizard, and wxVisualSetup can be used to generate project files that can be loaded and used in Visual Studio. If you want detailed control over your project or need to make specific modifications, however, it may be necessary to have an understanding of the individual settings.

Microsoft Visual Studio enables you to quickly and easily build wxWidgets projects by adding just a few wxWidgets directories and files into your project settings. Although the exact location for each setting is slightly different in each version of Visual Studio, the options are named roughly the same; please look at nearby options or consider alternate wordings if the setting isn't listed exactly as specified here.

1.

Create a new Win32 Project or Solution. Choose the most minimal options available.

2.

Open the Project Settings/Properties dialog.

3.

Find the Preprocessor Definitions under the C/C++ Settings. You will want to be sure that all of the following are defined: WIN32, __WXMSW__, _WINDOWS. If you are using a debug version of wxWidgets to build your project, you will also need to define _DEBUG, __WXDEBUG__. Note that some versions of Visual Studio will not show the C/C++ options until a C or C++ source file has been added to the project.

4.

Find the Additional Include Directories under the C/C++ settings and enter both the core include directory (such as c:\wxWidgets\include) and the include directory for the library configuration that you are using (such as c:\wxWidgets\lib\vc_lib\mswu). This configuration-specific include directory must be included for the compiler to find the setup.h that specifies what features are enabled for that build.

5.

Find the Additional Libraries Directories under the Link Settings and enter the directory where the compiled wxWidgets library files are located (such as c:\wxWidgets\lib\vc_lib).

6.

Find the Additional Dependencies or Object Modules setting to specify additional libraries to link with your application. The wxWidgets library names will vary depending on your build configuration but will follow the library naming conventions outlined in the installation appendix. For example, for the debug build, you would need to link at least wxmsw26d_core.lib and wxbase26d.lib. Depending on which wxWidgets features you are using, you may need to link with more of the libraries: wxbase26d_net.lib, wxbase26d_odbc.lib, wxexpatd.lib, wxjpegd.lib, wxmsw26d_adv.lib, wxmsw26d_grid.lib, wxmsw26_gl.lib, wxmsw26d_html.lib, wxmsw26d_xrc.lib, wxmsw26d_xml, wxpngd.lib, wxregexd.lib, wxtiffd.lib, and wxzlibd.lib. Again, remember the build configuration postfixes for the build you are using. You can always look at the compiled library files for a complete list of libraries.

7.

The Win32 libraries that you need to link, depending on your build configuration and what features you have enabled, could include some or all of the following: kernel32.lib, user32.lib, gdi32.lib, winspool.lib, comdlg32.lib, advapi32.lib, shell32.lib, ole32.lib, oleaut32.lib, uuid.lib, odbc32.lib, odbccp32.lib, winmm.lib, comctl32.lib, rpcrt4.lib, and wsock32.lib. Visual Studio usually adds some or all of these libraries when the project is created. Not all libraries are always needed; for example, if you do not use sockets, you would not need to link wsock32.lib.

8.

Find the Run-time Library selection from the C/C++ Code Generation settings and select either Multithread DLL or Multithread Debug DLL. You will not be able to link your program using the single-thread libraries or the non-DLL libraries. If you see a handful of linking errors about Windows symbols already being defined, you probably did not select a DLL run-time library.

9.

You can now add your source files to the project, if you have not already done so, and build your wxWidgets application.

Troubleshooting

If you receive any compile or link errors when building, double-check that you carefully followed all of the steps in the previous section to specify the include directories, the library directories, the wxWidgets and Win32 libraries, and the correct run-time library. You can also compare the project settings in any of the samples to the settings in your own project, looking for any discrepancies. Some developers start with a sample application's project file so that most of the settings are already defined correctly.

Some common error messages and solutions include the following:

  • Cannot open include file: 'wx/wx.h': No such file or directory This happens in two situations. One, the library itself hasn't been compiled yet; see Appendix A. Two, the library's include directory cannot be found (for example, c:\wxWidgets\lib\vc_lib\mswd); check that it is listed in the additional include directories.

  • Cannot open include file: 'wx/setup.h': No such file or directory The library's include directory cannot be found (such as c:\wxWidgets\ lib\vc_lib\mswd); check that it is listed in the additional include directories.

  • Cannot open file wxmswXXXX Either the libraries haven't been compiled or the wxWidgets libraries cannot be found because the directories have not been added to the additional library paths. Ensure that the library directory containing your compiled wxWidgets library has been added to the additional libraries.

  • Unresolved symbols to wxWidgets classes Some or all of the necessary wxWidgets library modules could not be found. Examine the symbols listed to determine the missing libraries, check the previous list of libraries, and add any missing library modules.

  • Unresolved symbols to Windows functions The linker could not find the Windows symbols needed to link your application. Ensure that the Windows libraries are included in the list of modules to be linked.

Using Multiple Configurations

Visual Studio creates two project configurations, debug and release, when you create a new project. Most wxWidgets developers test their applications using a debug build of wxWidgets to benefit from the debug information and the run-time assertions that may indicate certain problems. You will need to re-enter most of the settings for each different project configuration that you use keeping in mind which wxWidgets build the project configuration will be using. To save some time, you can copy one configuration rather than manually re-creating all of the settings each time.

The sample applications have over a dozen project configurations if you want to see how the settings may differ for each configuration.

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net