2

I have searched for this topic and found this and this, but it only seems to either pertain to building wxWidgets or do not contain an answer to my question.

I have built the static libs für wxWidgets on Windows successfully, but I am now struggling to correctly include the libraries to my project using Cmake. This is my CMakeLists.txt:

set(PROJECT_NAME wxapp)
project(${PROJECT_NAME})
cmake_minimum_required(VERSION 2.8)
    
set(SRC_LIST main.cpp app.cpp app.h frame.cpp frame.h)
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
    
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
    
set(wxWidgets_USE_LIBS ON)
set(wxWidgets_CONFIGURATION msw)

I have set the WXWIN path variable correctly. Yet, CMake throws an error with this configuration:

Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS net gl core base)

I have tried multiple suggestions, like using downloading prebuild dynamic libraries and adding them manually as suggested here, e.g.

set(wxWidgets_ROOT_DIR $ENV{WXWIN})
set(wxWidgets_LIBRARIES $ENV{WXWIN}/include)
set(wxWidgets_INCLUDE_DIR $ENV{WXWIN}/lib/vc14x_x64_dll)

include_directories(includes $ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll)

link_directories($ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll) # this seems to be a discouraged/deprecated method

but all to no avail.

17
  • 1
    "I have built the static libs for wxWidgets on Windows successfully" - But the name of vc14x_x64_dll directory suggests that you have .dll libraries, that is dynamic ones. Anywhere, what exact value you have assigned to wxWidgets_ROOT_DIR variable and what layout of files under that directory? Commented Sep 30, 2020 at 18:16
  • You need to set those variables before calling find_package. Also, see the search path here: cmake.org/cmake/help/latest/command/… Commented Sep 30, 2020 at 18:16
  • Welcome to Stack Overflow! Did you try Googling the error message? When doing so, I found this and this question, which appear to have helpful suggestions. Did you try these? Commented Sep 30, 2020 at 18:18
  • @StephenNewell: Documentation for find_package describes search procedure only for CONFIG files. But message Could NOT find wxWidgets (missing: ...) implies that MODULE mode has been used, and corresponded "Find" script has been found by CMake. The search procedure implemented by this script is described in the script itself (and in the corresponded doc page) and isn't standardized by find_package. Commented Sep 30, 2020 at 18:21
  • 1
    @Tsyvarev: Yes, I have this file under D:\libs\wxWidgets\include\wx\wx.h with my WXWIN set to D:\libs\wxWidgets. That path should work, right? Commented Sep 30, 2020 at 19:01

1 Answer 1

3

WORKAROUND (at least it works for me):

I changed the find_package command from the suggested statement:

find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)

to

find_package(wxWidgets 3.1 REQUIRED)

A user in this post had this included in his/her CMake file and out of deperation, I tried this and it actually worked. Seems like the configuration of CMake under certain unknown circumstances won't function correctly with the statement provided in the instructions. If I change the command to the new statement my static build as well as self- and precompiled dlls are flawlessly identifed by CMake.

I also cleared the CMake cache, inspired by this post. According to this post, there seems to be an issue with Windows and the CMake cache in some situations, but the reasons escape me. I could replicate the behaviour observed by the user there:

Under Windows, you have to point to the installation directory, e.g.

set(wxWidgets_ROOT_DIR "C:/wxWidgets-3.1.3") set(wxWidgets_LIB_DIR "C:/wxWidgets-3.1.3/lib/vc14x_x64_dll")

But then the behavior is still strange. When i use CMake GUI (3.16, latest), behavior is like this

  1. delete cache (just to be consistent)
  2. press 'configure' button --> fail: CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message): Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS core base qa adv net html gl propgrid richtext)
  3. press 'configure' button again --> success

I also have observed some inconsistent behaviour of CMake within the IDEs CLion and CodeBlocks when clearing the cache and reloading the project.

So, exactly how the cache clearing plays into the resolution of my issue, I don't know. But if I merely clear the cache, reload my project and leave the CMake instruction at find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net), CMake won't find my installation despite the WXWIN path being set correctly.

If you know more about this, I am happy to be corrected.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I meat the same issue here, see discussion on msys2's github issue link here: wxWidgets is not found from CMake when using Ninja in MSYS · Issue #10963 · msys2/MINGW-packages, the result message is quite strange, ` Could NOT find wxWidgets (missing: core base) (found suitable version "3.1.5", minimum required is "3.1") `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.