Natwar Singh
Natwar Singh

Reputation: 2275

how to setup wxwidgets on windows for visual studio 2005

i am try to do some GUI stuff and i want to setup wxWidget for visual studio 2005 on windows 7. I read may tutorial and help in last few days but all of them are showing different ways. and none of them work for me. in include c:/wxWidgets-2.9.4/include and /lib directories to visual studio but still it showing wx/setup.h not found. can any one please give a tutorial for setup wxWidget from scratch.(from downloading required packages to full working example). because i am also confuse which one i should download, they provide many zip forders.

Upvotes: 3

Views: 2602

Answers (2)

tinman
tinman

Reputation: 6608

The reason there are many zip archives is that from 2.9 onwards they are providing pre-built binary packages for each MSVC version. I have never used these so I cannot comment on those, but they might save you a lot of time building the sources and give you an official library.

I have used the MSW setup package and built from source. This is what I do and it works well for me (except I currently use wx292, VS2008 and Windows 7).

Download the wxWidgets 2.9.4 MSW setup package.

Install it. I assume it will create a directory in c:\wxWidgets-2.9.4.

Create a batch file c:\wxwidgets-2.9.4\build.bat with the following contents. You should replace myvendor with your name so it is clear that it is not an official wxWidgets library build (it will be put in the filenames, so avoid spaces).

@echo off
PUSHD build\msw
call :make

cd ..\..\samples
call :make

cd ..\demos
call :make

cd ..\utils
call :make

POPD
GOTO :EOF

@REM Perform builds with all desired configurations
:make
@REM x86 debug & release multiple DLLs Unicode
nmake -f makefile.vc MONOLITHIC=0 SHARED=1 UNICODE=1 BUILD=debug VENDOR=myvendor
nmake -f makefile.vc MONOLITHIC=0 SHARED=1 UNICODE=1 BUILD=release VENDOR=myvendor

@REM x86 debug & release multiple static libs Unicode
nmake -f makefile.vc MONOLITHIC=0 SHARED=0 UNICODE=1 BUILD=debug VENDOR=myvendor
nmake -f makefile.vc MONOLITHIC=0 SHARED=0 UNICODE=1 BUILD=release VENDOR=myvendor

Open a Visual Studio 2005 command prompt from the Start Menu. This will set up the path to your compiler and libraries correctly.

Change directory to wxWidgets: cd c:\wxWidgets-2.9.4.

Run the build.bat

It should complete after a few hours depending on your computer specifications, or you can REM out the builds for the samples, utils and demos to reduce the time (thanks @ravenspoint). You can also see the examples in c:\wxWidgets-2.9.4\samples and get the Visual Studio project settings from the sample projects to use in your own projects (for example C:\wxWidgets-2.9.4\samples\dialogs\dialogs_vc8.vcproj).

After building the library you will end up with some additional directories under C:\wxWidgets-2.9.4\lib which contains the built libraries, dlls and any build specific headers for that variant. The following directories are created from the builds in my batch script and are tagged with the toolset (vc for Visual C in this case, but could be version specific, e.g. vc80 or a fixed version depending on your build settings) and the type of library. msw in the directory and filenames means MicroSoft Windows. u in the directory and filenames means Unicode. d at the end of directory and filenames means Debug.

  • C:\wxWidgets-2.9.4\lib\vc_lib: Visual C (vc) Static library (lib) versions of wxWidgets
    • C:\wxWidgets-2.9.4\lib\vc_lib\mwsu: MicroSoft Windows Unicode specific files
    • C:\wxWidgets-2.9.4\lib\vc_lib\mwsud: MicroSoft Windows Unicode Debug specific files
    • Also contains a mixture of static libraries for release and debug
  • C:\wxWidgets-2.9.4\lib\vc_dll: Visual C (vc) DLL (dll) versions of wxWidgets
    • C:\wxWidgets-2.9.4\dll\vc_lib\mwsu: MicroSoft Windows Unicode specific files
    • C:\wxWidgets-2.9.4\dll\vc_lib\mwsud: MicroSoft Windows Unicode Debug specific files
    • Also contains a mixture of DLLs and import libraries for release and debug

In order to use the newly built libraries in your own projects you can follow these steps (I use VS2008 so some of the configuration names might be slightly different):

When you create a new project you need to go to the project properties.

Under Configuration properties -> General -> Environment add the following (so your application can find the DLLs) if you are using the DLLs:

PATH=C:\wxWidgets-2.9.4\lib\vc_dll

Under C/C++ -> General -> Additional Include Directories you need to add the wxWidgets includes in the following order:

  1. "C:\wxWidgets-2.9.4\include\msvc"
  2. "C:\wxWidgets-2.9.4\include"

The reason for including directory 1 first is that there is a wx\setup.h in that directory. When you include that it tries to determine what compiler, type of library (static or DLL), whether you are using Unicode or not and whether it is debug or release and it automatically includes the correct real wx/setup.h from the one of the subdirectories of C:\wxWidgets-2.9.4\lib.

You then need to go to C/C++ -> Preprocessor -> Preprocessor Definitions and add the following lines:

__WXMSW__

If you want to use the DLL version of wxWidgets instead of the static library you need to add the following line:

WXUSINGDLL

Under Linker -> General -> Additional Linker Directories you need to add the following path if you are using the static libraries:

"C:\wxWidgets-2.9.4\lib\vc_lib"

Or the following path if you are using the DLLs:

"C:\wxWidgets-2.9.4\lib\vc_dll"

In Linker -> Input -> Additional Dependancies you will probably need to add at least the following:

comctl32.lib rpcrt4.lib

And under Resources -> General -> Additional Include Directories you will need to add the following path:

C:\wxWidgets-2.9.4\include

Upvotes: 3

ravenspoint
ravenspoint

Reputation: 20457

@tinman's recipe allows you to build eveything, but it takes a long time.

A simpler recipe, which only builds the necessary library:

  • Do the installation using the setup package.

  • Find the microsoft visual studio build folder. On my installation this is C:\wxWidgets-2.9.n\build\msw

  • Find the solution for your version of visual studio ( e.g. wx_vc8.sln ) and open it.

  • Select the configuration you intend to use when building your applications. ( e.g. DLL Release )

  • Build the solution.

Done. It should take about five minutes on any reasonably powerful machine.

Upvotes: 4

Related Questions