1

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.

Ðаn
  • 10,934
  • 11
  • 59
  • 95
KamikaZimon
  • 65
  • 2
  • 8
  • 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? – Tsyvarev Sep 30 '20 at 18:16
  • You need to set those variables before calling `find_package`. Also, see the search path here: https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure – Stephen Newell Sep 30 '20 at 18:16
  • Welcome to Stack Overflow! Did you try Googling the error message? When doing so, I found [this](https://stackoverflow.com/q/48945965/3987854) and [this](https://stackoverflow.com/a/41578736/3987854) question, which appear to have helpful suggestions. Did you try these? – Kevin Sep 30 '20 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](https://cmake.org/cmake/help/v3.0/module/FindwxWidgets.html)) and isn't standardized by `find_package`. – Tsyvarev Sep 30 '20 at 18:21
  • Yes, I have built the static libs, but have then followed one hint and downloaded the dynamic libs as well to eliminate the possibilities of building error. My wxWidgets_ROOT_DIR is my wxWidgets main directory, which contains the include and lib directory, currently located at D:\libs\wxWidgets – KamikaZimon Sep 30 '20 at 18:24
  • @squareskittles: I have found those and tried them both prior to asking this question. One of the links also refer to FindwxWidgets, which states to link the libs manually. – KamikaZimon Sep 30 '20 at 18:31
  • Hm, actually the script [FindwxWidgets.cmake](https://github.com/Kitware/CMake/blob/master/Modules/FindwxWidgets.cmake) (used by `find_package(wxWidgets)`) searches under directories specified both in `WXWIN` and `wxWidgets_ROOT_DIR` **environment** variables. So, having `WXWIN` environment variable should be sufficient for hint CMake about your wxWidgets installation. What is searched under this directory is `include/wx/wx.h` file. Do you have this file? What is **absolute path** to it on your machine? By knowing the absolute path we could suggest value of `WXWIN` variable which should work. – Tsyvarev Sep 30 '20 at 18:55
  • @user14264698, why do you want to use CMake? wxWidgets provides solutions to every compiler and most used IDEs on the market... – Igor Sep 30 '20 at 18:57
  • 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? – KamikaZimon Sep 30 '20 at 19:01
  • @Igor: I am using CLion and to my knowledge, wxWidgets should work without issues with CMake. – KamikaZimon Sep 30 '20 at 19:01
  • Yes, the path `D:\libs\wxWidgets` should work.. assuming you use the latest CMake version. But what actual CMake version do you use? – Tsyvarev Sep 30 '20 at 19:03
  • The CMake version is 3.17.3 and I am using CLion with MingW. Is it a problem that I used the user environment path variable and not the system environment path variable? – KamikaZimon Sep 30 '20 at 19:05
  • a `echo %WXWIN%` points to `D:\libs\wxWidgets` so the path should be readable for CMake – KamikaZimon Sep 30 '20 at 19:07
  • Have you used any of the CMake trace options to help debug the issue? You also have a few typos and are setting the wrong variables and are also not following the Sample usage in the 3.17.3 documentation that states `Note that for MinGW users the order of libs is important!` and `find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)` – fdk1342 Oct 01 '20 at 01:08
  • @fdk1342: could you elaborate on the typos and wrong variables? – KamikaZimon Oct 01 '20 at 04:56
  • From what I can tell, I am sticking to the sample usage. I am using `find package` before `include` and `target_link_libraries` which is in accordance with the instructions. I copied and pasted the `find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)` also to no avail. – KamikaZimon Oct 01 '20 at 05:29
  • It looks like you are trying to override the variables that would have been set by the module, but using `$ENV{WXWIN}` without quoting or otherwise accounting for backslashes vs forward slashes. The documentation does state that `wxWidgets_ROOT_DIR` and `wxWidgets_LIB_DIR` can be used to give the hint of where to find the items *before* calling `find_package`. In this case you should still be using forward slashes as that is what CMake expects; properly quoting backslashes may work. Also making these kinds of changes will only work after clearing the cache. – fdk1342 Oct 01 '20 at 14:07

1 Answers1

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.

KamikaZimon
  • 65
  • 2
  • 8
  • 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](https://github.com/msys2/MINGW-packages/issues/10963), the result message is quite strange, ` Could NOT find wxWidgets (missing: core base) (found suitable version "3.1.5", minimum required is "3.1") ` – ollydbg23 Apr 29 '22 at 14:45