wxWidgets 3.1 error finding two libraries with MinGW

I’ve had this working before but…

I’m building a cross platform project that uses wxWidgets. Currently I’m cross-compiling windows 64bit from Fedora linux. The project performs a bootstrap build of wxWidgets if required. This part is working fine and the main wxWindows libraries are being found.

The CMake FindwxWindows module seems to treat the regex and scintilla libraries as “support” libraries and not main libraries?

Initially I got a very unhelpful error that wxWindows was not found without further context, I had to turn on all the debug messages to find the problem:

wxWidgets not found due to following missing libraries:
wxregexu-3.1-x86_64-w64-mingw32 wxscintilla-3.1-x86_64-w64-mingw32

This should probably be changed to a real message instead of debug.

The libraries exist:

$ ls -1 external/dist/lib/
libportaudio.a
libportaudio.la
libwx_baseu-3.1-x86_64-w64-mingw32.a
libwx_baseu_net-3.1-x86_64-w64-mingw32.a
libwx_baseu_xml-3.1-x86_64-w64-mingw32.a
libwx_mswu_adv-3.1-x86_64-w64-mingw32.a
libwx_mswu_aui-3.1-x86_64-w64-mingw32.a
libwx_mswu_core-3.1-x86_64-w64-mingw32.a
libwx_mswu_gl-3.1-x86_64-w64-mingw32.a
libwx_mswu_html-3.1-x86_64-w64-mingw32.a
libwx_mswu_media-3.1-x86_64-w64-mingw32.a
libwx_mswu_propgrid-3.1-x86_64-w64-mingw32.a
libwx_mswu_qa-3.1-x86_64-w64-mingw32.a
libwx_mswu_ribbon-3.1-x86_64-w64-mingw32.a
libwx_mswu_richtext-3.1-x86_64-w64-mingw32.a
libwx_mswu_stc-3.1-x86_64-w64-mingw32.a
libwx_mswu_webview-3.1-x86_64-w64-mingw32.a
libwx_mswu_xrc-3.1-x86_64-w64-mingw32.a
libwxregexu-3.1-x86_64-w64-mingw32.a
libwxscintilla-3.1-x86_64-w64-mingw32.a

I found where the libraries are being “found” and added some of my own debug:

-- Looking for wxregexu-3.1-x86_64-w64-mingw32
-- Looking for wxscintilla-3.1-x86_64-w64-mingw32
-- Looking for expat
-- Looking for png
-- Looking for jpeg
-- Looking for tiff
-- Looking for z
-- Looking for rpcrt4
-- Looking for oleaut32
-- Looking for ole32
-- Looking for uuid
-- Looking for lzma
-- Looking for uxtheme
-- Looking for winspool
-- Looking for winmm
-- Looking for shell32
-- Looking for shlwapi
-- Looking for comctl32
-- Looking for comdlg32
-- Looking for advapi32
-- Looking for version
-- Looking for wsock32
-- Looking for gdi32
-- Looking for oleacc

So does all the -3.1… stuff need to be stripped off for it to find it? The relevant part of the module reads:

# Check that all libraries are present, as wx-config does not check it
set(_wx_lib_missing "")
foreach(_wx_lib_ ${wxWidgets_LIBRARIES})
  if("${_wx_lib_}" MATCHES "^-l(.*)")
    set(_wx_lib_name "${CMAKE_MATCH_1}")
    unset(_wx_lib_found CACHE)
    message(STATUS "Looking for ${_wx_lib_name}")
    find_library(_wx_lib_found NAMES ${_wx_lib_name} HINTS ${wxWidgets_LIBRARY_DIRS})
    if(_wx_lib_found STREQUAL _wx_lib_found-NOTFOUND)
      list(APPEND _wx_lib_missing ${_wx_lib_name})
    endif()
    unset(_wx_lib_found CACHE)
  endif()
endforeach()

Any pointers?

Thanks,
Richard

It’s actually worse than I thought. It’s completely skipping the static libraries:

# Check that all libraries are present, as wx-config does not check it
set(_wx_lib_missing "")
foreach(_wx_lib_ ${wxWidgets_LIBRARIES})
  if("${_wx_lib_}" MATCHES "^-l(.*)")
    set(_wx_lib_name "${CMAKE_MATCH_1}")
    unset(_wx_lib_found CACHE)
    message(STATUS "Looking for ${_wx_lib_name}")
    find_library(_wx_lib_found NAMES ${_wx_lib_name} HINTS ${wxWidgets_LIBRARY_DIRS})
    if(_wx_lib_found STREQUAL _wx_lib_found-NOTFOUND)
      list(APPEND _wx_lib_missing ${_wx_lib_name})
    endif()
    unset(_wx_lib_found CACHE)
  endif()
endforeach()

This only picks up shared libraries (-l…)

However, wx-config is also to blame, is includes the regex and scintilla as shared libraries even though they’re static…

wxWidgets_LIBRARIES=-L/home/build/build/freedv/external/dist/lib;;;-Wl,--subsystem,windows;-mwindows;/home/build/build/freedv/external/dist/lib/libwx_mswu_aui-3.1-x86_64-w64-mingw32.a;/home/build/build/freedv/external/dist/lib/libwx_baseu_net-3.1-x86_64-w64-mingw32.a;/home/build/build/freedv/external/dist/lib/libwx_mswu_html-3.1-x86_64-w64-mingw32.a;/home/build/build/freedv/external/dist/lib/libwx_mswu_core-3.1-x86_64-w64-mingw32.a;/home/build/build/freedv/external/dist/lib/libwx_baseu-3.1-x86_64-w64-mingw32.a;-L/usr/x86_64-w64-mingw32/sys-root/mingw/lib;-lwxregexu-3.1-x86_64-w64-mingw32;-lwxscintilla-3.1-x86_64-w64-mingw32;-lexpat;-lpng;-ljpeg;-L/usr/x86_64-w64-mingw32/sys-root/mingw/lib;-ltiff;-lz;-lrpcrt4;-loleaut32;-lole32;-luuid;-llzma;-luxtheme;-lwinspool;-lwinmm;-lshell32;-lshlwapi;-lcomctl32;-lcomdlg32;-ladvapi32;-lversion;-lwsock32;-lgdi32;-loleacc

Thanks,
Richard

It seems like a bug should be filed about this? I’m not familiar enough with wxWidgets to know if wx-config or FindWxWidgets is to blame here though…

Probably both…

Please file an issue with upstream and CMake about this (please link the upstream issue from CMake’s so we can incorporate anything from there in the FindWxWidgets change more easily). Unfortunately these kinds of things usually require some dedicated time to investigate, so I don’t have the time in the foreseeable future myself, but being in the issue tracker should help raise awareness for others too.