Search code examples
visual-c++cmakewxwidgets

wxWidgets fails to build due to missing wxxml.lib


Apparently anything GUI-related in terms of components involves XML. I cannot go around actually configuring and building wxWidgets from source because of that. I'm new to wxWidgets.

My current setup is on Win10 with MSVC v141 (Visual Studio 2017) with the latest CMake version (currently 3.21).

Inside the config.cmake of the wxWidgets projects (using latest master branch) I see

wx_get_dependencies(EXTRALIBS_XML xml)

I am also calling CMake with -DwxUSE_XML=ON (among other parameters) but this still leads to:

  • the XML dependency is nowhere to be found
  • respectively it's not built

Linking then fails with the following error:

LINK : fatal error LNK1104: cannot open file 'wxxml.lib' [C:\Users\...\CMakeBuilds\ef5b5ada-ee42-7735-988a-ae37c735ccff\build\deps\build\wxwidgets\libs\qa\wxqa.vcxproj]

What library is actually wxWidgets using and how do I trigger it's retrieval and accordingly configuration and building? Since I am adding wxWidgets to my CMake project as an ExternalProject component, I would appreciated something in that line of thought. However any kind of information regarding this issue is more than welcome especially since it will shine light on how to configure other features (if I want them in the future) such as WebView.


Solution

  • The wxxml.lib issue is fixed now. While fixing it I also discovered a bug (of sort) in the build system of wxWidgets.

    The reason why it failed to build this library in particular was actually quite simple but due to the lack of knowledge in the dependencies of wxWidgets. I thought that wxWidgets, given it depends on XML so much, has its own XML parser. Well, not really. The wxXML component actually uses and underlying 3rd party dependency called EXPAT, which - as you can see in my question - I have deactivated since it was giving me issues during the build (due to the still present problem of not being able to automatically retrieve dependencies).

    What I did was to clone the libexpat repository, add it as an ExternalProject, set the variables for the libraries and include directory and pass them onto my wxWidgets project. But there is a catch...

    The expat.cmake file looks as follows:

    #############################################################################
    # Name:        build/cmake/lib/expat.cmake
    # Purpose:     Use external or internal expat lib
    # Author:      Tobias Taschner
    # Created:     2016-09-21
    # Copyright:   (c) 2016 wxWidgets development team
    # Licence:     wxWindows licence
    #############################################################################
    
    if(wxUSE_EXPAT STREQUAL "builtin")
        # TODO: implement building expat via its CMake file, using
        # add_subdirectory or ExternalProject_Add
        wx_add_builtin_library(wxexpat
            src/expat/expat/lib/xmlparse.c
            src/expat/expat/lib/xmlrole.c
            src/expat/expat/lib/xmltok.c
        )
        set(EXPAT_LIBRARIES wxexpat)
        set(EXPAT_INCLUDE_DIRS ${wxSOURCE_DIR}/src/expat/expat/lib)
    elseif(wxUSE_EXPAT)
        find_package(EXPAT REQUIRED)
    endif()
    

    I would use the *.cmake files of the 3rd party dependencies stored inside <ROOT_OF_WXWIDGETS_PROJECT>/build/cmake/lib to determine which variables I need to set if builtin is selected as the value for the respective library. Since I want to use my own I need sys (e.g. -DwxUSE_EXPAT=sys as a CMAKE_ARGS inside my wxWidgets ExternalProject) and also to pass the headers and libraries accordingly.

    Given the file above one would assume that EXPAT_LIBRARIES is required. However after failing to build (yet again) and seeing that the reason was the activated expat build and that it was set as builtin I checked the log in detail and found the following error:

    Could NOT find EXPAT (missing: EXPAT_LIBRARY) (found version "2.2.6")

    Notice the EXPAT_LIBRARY. After passing it (-DEXPAT_LIBRARY=...) my build was complete. For me this is a bug or simply inconsistency between the dependency cmake file and the rest of the wxWidgets project.

    It is important to note that I do not retrieve the external dependency through wxWidgets itself (see config.cmake and more precisely the macro wx_get_dependencies(...)). This solves the problem with a basic configuration and build of wxWidgets but if you don't want to tackle every dependency of wxWidgets on your own (why should you?), I recommend looking for a solution where the dependencies (at least the ones you don't want to deal with) are automatically retrieved, configured and build as builtin.