2

I want to compile a source code on windows using CMake, it uses wxWigets library. I downloaded the wxWigets from the page: https://www.wxwidgets.org/

After building by Visual Studio, I got the library /lib file. I have already set PATH for wxWidgets_LIBRARIES and wxWidgets_INCLUDE_DIRS. But the following errors cannot be resolved.

CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
      Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
      wxWidgets_INCLUDE_DIRS)
    Call Stack (most recent call first):
      C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
      C:/Program Files/CMake/share/cmake-3.11/Modules/FindwxWidgets.cmake:953 (find_package_handle_standard_args)
      CMakeLists.txt:52 (find_package)

I also read the thread about this problem in: CMake could not find wxWidgets on Windows But there is no solution for my case.

Karim
  • 252
  • 1
  • 4
  • 17

2 Answers2

4

You may specify wxWidgets_ROOT_DIR variable to point to your wxWidgets installation.

As far as I understand, you may set either CMake variable via -D option to cmake:

cmake -DwxWidgets_ROOT_DIR:PATH=D:/path/to/wxWidgets/ ...

or you may set environment variable

set wxWidgets_ROOT_DIR=D:\path\to\wxWidgets\ ...

(Note that CMake path variables use "universal" directory separator '/', but environment variables use native directory separator, '\' for Windows).

This variable is described in documentation for FindwxWidget.


Using wxWidgets_LIB_DIR variable could be tricky, see that question.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • I think I have already set the `wxWidgets_ROOT_DIR`, but still no lucky.. – user3875388 Sep 19 '20 at 17:51
  • 1
    do you find any solution to this? I run into the exactly same issue here. – Youshikyou Mar 27 '21 at 09:36
  • @ZhiqiangYang: Do you mean the problem you described in [that question](https://stackoverflow.com/questions/66736886/windows-vs-code-wxwidgetss-include-wx-wx-h-not-found)? No, it is not "exactly same issue here". The asker got error from the `find_package(wxWidgets)` and setting `wxWidgets_ROOT_DIR` should fix that error. In your case, `find_package(wxWidgets)` **succeed** and you got the error message from the compiler. – Tsyvarev Mar 27 '21 at 10:20
  • In a simple way to explain, after I reinstalled the wxWidgets I cannot compile it. Now I have this "CMake Error Could NOT find wxWidgets". So that's why I ask if there is a solution to "not find wxWidgets" – Youshikyou Mar 27 '21 at 11:00
  • 1
    Setting `wxWidgets_ROOT_DIR` should help. Check that you set proper path and with proper separator (if you set CMake variable, then path separator is always ``/``, if you set environment variable, then path separator on Windows is ``\``). As a self-check, check that the directory, which you specified in `wxWidgets_ROOT_DIR` variable, actually contains `include/wx/wx.h` file. If nothing helps, then you are free to ask a new question, where you could describe all details about your problem. – Tsyvarev Mar 27 '21 at 11:06
  • @Tsyvarev I get the same error but only with clang on windows but not msvc. What can the compiler have to do with that? – David Zanger Apr 29 '22 at 07:30
  • What kind of error do you got? The question post is about `Could NOT find wxWidgets` error, which is NOT from the compiler. You are better to prepare your own question post, where you can describe your problem in more details. Also, in your question post you could describe which **solutions** from other questions you have **tried** and what result have you got. – Tsyvarev Apr 29 '22 at 07:56
1

I have a solution witch can solve this problem. there is something wrong with the FindwxWidgets.cmake File Firstly, delete the file C:/Program Files/CMake/share/cmake-3.11/Modules/FindwxWidgets.cmake

instead, you can find the package by using wxWidetsConfig.cmake file YOUR_PATH\wxWidgets\lib\cmake\wxWidgets\wxWidgetsConfig.cmake.

add the flowing codes in your CMakeLists.txt and you can use wxWidgets

# set(CMAKE_PREFIX_PATH  C:/dev/wxWidgets) also works
set(CMAKE_PREFIX_PATH  C:/dev/wxWidgets/lib/cmake/wxWidgets)

find_package(wxWidgets COMPONENTS core base REQUIRED)

add_executable(wxwdemo WIN32 main.cpp)

target_link_libraries(wxwdemo ${wxWidgets_LIBRARIES})

target_include_directories(wxwdemo PUBLIC ${wxWidgets_INCLUDE_DIRS})

then it works

lvyaqiao
  • 11
  • 1