Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve qt5 (packages not found) cmake errors in mac?

Tags:

c++

macos

cmake

qt

qt5

I get these following errors during build of a file using CMake:

CMake Warning at CMakeLists.txt:33 (FIND_PACKAGE):

By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5Core", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt5Core" with any of the following names:

    Qt5CoreConfig.cmake
    qt5core-config.cmake

Anybody know how to solve this? Thanks in advance

like image 784
D.vijay Avatar asked Aug 03 '16 14:08

D.vijay


People also ask

How does Cmake find qt5?

In order for find_package to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the Qt5_DIR must be set in the CMake cache to the location of the Qt5WidgetsConfig. cmake file. The easiest way to use CMake is to set the CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.

Where is Qt6 config Cmake?

This time, I found a Qt6Config. cmake there (inside C:\Qt\6.3. 1\msvc2019_64\lib\cmake\Qt6).


3 Answers

Maybe, you should try to add the proper path to the CMAKE_PREFIX_PATH variable in the environment or config.

export CMAKE_PREFIX_PATH=path_to/Qt/5.9/clang_64:$CMAKE_PREFIX_PATH

Replace path_to with your real path.

like image 182
user3857893 Avatar answered Oct 14 '22 16:10

user3857893


You should find the cmake packages in your Qt installation in:

<install_prefix>/lib/cmake

Assuming <install_prefix> is the root path of your installation. Set the variable Qt5_DIR to <install_prefix>/lib/cmake/Qt5 in your configuration and cmake should be able to find all the modules

like image 10
rgmt Avatar answered Oct 14 '22 18:10

rgmt


One possible cause for this error message is outdated CMake code like [1]

find_package(Qt5Core REQUIRED).

Then there is a good chance for solving the problem by changing to

find_package(Qt5 COMPONENTS REQUIRED Core).

[1] http://cmake.3232098.n2.nabble.com/debugging-CMAKE-PREFIX-PATH-td7596290.html

like image 3
Joachim W Avatar answered Oct 14 '22 17:10

Joachim W