Start wxWdigets programming on Windows

  |   Source

  • Download wxWidgets
  • Extracted it somewhere. "c:\wxWidgets-2.8.12", for example.
  • Create environment variable WXWIN with value "c:\wxWidgets-2.8.12"
  • Install Visual Studio (Express version is fine if you installed WIN32 SDK too)
  • Compile wxWidgets library by running the dos batch file:
@echo off
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"

nmake -f %WXWIN%\build\msw\makefile.vc UNICODE=1 BUILD=debug

nmake -f %WXWIN%\build\msw\makefile.vc UNICODE=1 BUILD=release

We use vcvars32.bat to set up the CLI tool chains.

"Unicode=1" because our application will support i18n.

  • Install CMake
  • Create a simple project with files main.cpp, main.hpp, CMakeLists.txt

main.cpp and main.hpp containts normal C++ code.

CMakeLists.txt is the project file for CMake:

PROJECT(main)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

# sets variable SOURCES to the project source files.

set(XRCS main_frame.xrc )

set(XRCS_DIR ${main_SOURCE_DIR}/rc)

if(CMAKE_COMPILER_IS_GNUCC) # needed for gcc 4.6+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") endif()

set( CPP_SOURCES main.cpp )

set( H_SOURCES main.hpp ) )

set(SOURCES ${CPP_SOURCES} ${H_SOURCES} )

# xrc -> xml, adv, html

set(wxWidgets_USE_LIBS xrc xml adv html core base)

find_package(wxWidgets REQUIRED)

include(${wxWidgets_USE_FILE})

#try to embed resource

foreach(XRC $latex {XRCS}) string(REGEX REPLACE "[.].*$" ".h" XRC_HEADER ${XRC}) set(XRC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${XRC_HEADER}) set(XRC ${XRCS_DIR}/${XRC}) add_custom_command(OUTPUT ${XRC_HEADER} COMMAND bin2c -c ${XRC} ${XRC_HEADER} MAIN_DEPENDENCY ${XRC} ) set(SOURCES ${SOURCES} ${XRC_HEADER}) endforeach(XRC)

set(INC )

if(UNIX AND NOT APPLE) include(FindPkgConfig) pkg_check_modules(GTK2 REQUIRED gtk+-2.0>=2.10) set(INC ${INC} ${GTK2_INCLUDE_DIRS}) endif()

#add other librarie

include_directories(${INC})

if(UNIX) add_definitions(-Wno-write-strings) endif()

if(WIN32) # WIN32 := subsystem is windows instead of console? add_executable(main WIN32 ${SOURCES}) else(WIN32) add_executable(main ${SOURCES}) endif()

set(LIBS ${wxWidgets_LIBRARIES} )

if(MINGW AND WIN32) set(LIBS ${LIBS} ole32 uuid oleaut32) endif()

target_link_libraries(main ${LIBS})

  • Running the below dos batch the create Visual Studio Project Files
@echo off

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"

cmake path/of/directory/which/contains/CMakeLists.txt/

  • Enjoy!

BTW, for other systems, see wxWiki.

Comments powered by Disqus