简体   繁体   中英

CMake cannot find wxWidgets library on macOS High Sierra

I was learning CMake and wanted to try it out to compile a test wxWidgets application, which I previously successfully compiled under Windows. However, I've never used CMake before, but back then I set it up using Visual Studio manually.

So I looked at some tutorials online, and compiled a basic hello world application (command line) in C++ using CMake, and it worked fine. Then I installed wxWidgets using brew.

brew install wxmac

It did install and I could run the wx-config tool successfully. I can also see the files in the finder. Then I added this to my CMakeLists.txt file.

project(wxWidgetsTest)

cmake_minimum_required(VERSION 2.8)

find_package(wxWidgets COMPONENTS core base wxSTC wxAUI REQUIRED)

include( "${wxWidgets_USE_FILE}" )

add_executable(
    ${PROJECT_NAME}
    main.cpp
    )

target_link_libraries(
    ${PROJECT_NAME}
    ${wxWidgets_LIBRARIES}
    )

But however, when I tried to generate the build files, I'm using the command:

cmake -G "Unix Makefiles" ..

And it fails saying that find_package cannot find the wxWidgets library. This is the error output:

CMake Error at /usr/local/Cellar/cmake/3.11.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.11.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.11.1/share/cmake/Modules/FindwxWidgets.cmake:953 (find_package_handle_standard_args)
  CMakeLists.txt:5 (find_package)

The wxWidgets library is installed at /usr/local/Cellar/wxmac/3.0.4/

What did I do wrong here?

After six hours of fiddling, I found a new configuration option in the findWxWidgets script which is a needed configuration.

All I had to do is to specify the location of the wx-config file.

cmake -G "Unix Makefiles" .. -DwxWidgets_CONFIG_EXECUTABLE=/usr/local/Cellar/wxmac/3.0.4/bin/wx-config

And it was able to find the wxWidgets library. Seems to be a simple error on my part.

This is the source where I found: http://cmake.3232098.n2.nabble.com/Can-t-find-wxWidgets-tp7591015p7591017.html

considering it a bug...

to work around, set CMAKE_FIND_ROOT_PATH to help cmake find the program. put following line before find_package(wxWidgets).

set(CMAKE_FIND_ROOT_PATH "/usr/local")

I find suspecious code in FindWidgets.cmake with comments

Support cross-compiling, only search in the target platform.

and it provide ONLY_CMAKE_FIND_ROOT_PATH option to find_program command. According to documentation, this option means only find program under 'root' path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM