Search code examples
visual-studiovisual-studio-2015wxwidgets

Getting started with wxWidgets and VisualStudio


I want to build C++ desktop applications using visual studio and wxWidgets on windows 7. I'm coming from C++ Builder.

I downloaded and built the wxWidgets libraries successfully and I can run the minimal_vc14 solution just fine. Now it comes time to create my Hello World app. I've created a new, empty C++ project and using NuGet added the wxWidgets template. Then I use class wizard to add a new class (Test3) with a base class of wxApp.

I immediately get 45 errors. The first of which is

Severity    Code    Description Project File    Line    Suppression State
Error (active)      cannot open source file "../../../lib/vc_dll/mswud/wx/setup.h"  Test3   c:\wxWidgets-3.1.0\include\msvc\wx\setup.h  121 

digging into that file I find the following bit. The last include statement is the problem line identified above, but the problem I think is in the wxConcat6 statement. All of those ../ lead nowhere. Shouldn't that point to $(WXWIN)?

// the real setup.h header file we need is in the build-specific directory,
// construct the path to it
#ifdef wxSUFFIX
    #define wxSETUPH_PATH \
        wxCONCAT6(../../../lib/, wxLIB_SUBDIR, /, wxTOOLKIT_PREFIX, wxSUFFIX, /wx/setup.h)
#else // suffix is empty
    #define wxSETUPH_PATH \
        wxCONCAT5(../../../lib/, wxLIB_SUBDIR, /, wxTOOLKIT_PREFIX, /wx/setup.h)
#endif

#define wxSETUPH_PATH_STR wxSTRINGIZE(wxSETUPH_PATH)

#include wxSETUPH_PATH_STR

Also, smaller problem but further up the setup.h file I see that WXUSINGDLL has been defined, but I want to use libs. I can't figure out where that is being set either.

Obviously there is a configuration step I missed somewhere. Please advise.


Solution

  • As usual the answer can be found by reading EVERYTHING.

    There are 2 things that need to be configured for this process to work correctly.

    1. After creating the project go to the project properties and set the character set to Unicode. The default is Multi-Byte. My next quest will be to find where to change the default!
    2. After installing the package template (or is it a template package?) go to the project properties and set shared to "statically linked build".

    enter image description here

    1. Presto changeo, you are ready to go. Add the following for the absolute minimum to make a compilable application. This is based on the tutorial here:creating-wxwidgets-programs-with-visual-studio-2015

      bool MyProjectApp::OnInit()
      {
          wxFrame* mainFrame = new wxFrame(nullptr, wxID_ANY, L"MyProject");
          mainFrame->Show(true);
          return true;
      }
      wxIMPLEMENT_APP(MyProjectApp);