Could NOT find wxWidgets | CMake issue

  c++, cmake, wxwidgets

so I was trying to link to wxWidgets with CMake, and I couldn’t get it to work. Here is my CMakeLists.txt.

cmake_minimum_required(VERSION 3.20.1)
set(CMAKE_CXX_STANDARD 20)
project(FormApplication)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(EXE_NAME run)

find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)
include(${wxWidgets_USE_FILE})

add_subdirectory(src) # creates an exe named ${EXE_NAME}
target_link_libraries(${EXE_NAME} PRIVATE ${wxWidgets_LIBRARIES})

I get the following error when running cmake -S . -G "Ninja" -B build

CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
  wxWidgets_INCLUDE_DIRS gl core base)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.20/Modules/FindwxWidgets.cmake:1025 (find_package_handle_standard_args)
  CMakeLists.txt:7 (find_package)

Why do I get this error? Every source I go to has a different answer, but none of them have worked so far. Some even say you can’t link to wxWidgets with cmake.
Please help, I’ve been trying to get this to work for a couple days already. Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT