CMAKE_PREFIX_PATH doesn't help CMake in finding Qt5
I installed the following missing packages:
sudo apt-get install qtbase5-dev
sudo apt-get install qtdeclarative5-dev
Attaching any kind of prefix is not required now:
CMakeList:
:~/junk/qtquick_hello_cmake$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(qtquick_hello_cmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Quick Core REQUIRED)
qt5_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" "qml.qrc")
qt5_use_modules(${PROJECT_NAME} Quick Core)
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Quick)
New output:
:~/junk/qtquick_hello_cmake$ ls
build CMakeLists.txt main.cpp main.qml qml.qrc
:~/junk/qtquick_hello_cmake$ cd build/
:~/junk/qtquick_hello_cmake/build$ rm -rf *
:~/junk/qtquick_hello_cmake/build$ cmake ../
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/.../junk/qtquick_hello_cmake/build
Errors are gone now.
Thanks to:
https://answers.ros.org/question/236324/could-not-find-a-package-configuration-file-provided-by-qt5widgets/
https://askubuntu.com/questions/508503/whats-the-development-package-for-qt5-in-14-04
CMAKE_PREFIX_PATH for Qt5
Since it has solved your question, I am just going to put it as an answer here. I will improve this section more in detail later.
If you are using cmake use find_package
to find the package and then link to your
binary in later stage.
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 Qt5Config.cmake file. The easiest way to use CMake is to set the
CMAKE_PREFIX_PATH environment variable to the install prefix of Qt 5.
If you just want to find the Qt modules then just set the Qt5_DIR
ex: Qt5_DIR="/Users/bob/Qt/5.12.7/clang_64/lib/cmake/Qt5"
when building with CMake
you can use Qt5_DIR or CMAKE_PREFIX_PATH, both should work.
More explanation about building with CMake can be found here
cmake find_packages(QT5) does not use correct version of QT binaries despite setting prefix path
I figured it out...
This was a cmake cache issue most likely. I had thought It might have been this type of issue before, but I was clearing the wrong cmake version cache. I installed a different version of cmake on my computer (which is newer) than the one clion came with (I told it to use the default version i hadn't installed). So by deleting that cmake's cache it did absolutely nothing to my clion version of cmake (so IIRC from reading cmake docs, things like CMAKE_PREFIX_PATH would use cache versions by default) This made it impossible to switch off of anaconda version despite it, for example, when I put in the wrong version info IE find_package(Qt5 8.0 REQUIRED COMPONENTS Core Widgets Gui)
clearly understanding and knowing the installation directory of the 5.8.0 directory (since it listed it):
Could not find a configuration file for package "Qt5" that is compatible
with requested version "8".
The following configuration files were considered but not accepted:
C:/msys64/mingw64/lib/cmake/Qt5/Qt5Config.cmake, version: 5.8.0
C:/ProgramData/Anaconda3/Library/lib/cmake/Qt5/Qt5Config.cmake, version: 5.6.2
Cmake couldn't let me use that version when I set the cmake path var, switching between both versions of cmake now builds correctly (i believe clion might clear cache when you switch from the internal version, I'm not sure). So hopefully any one else who happens upon this particular problem will now be able to fix it.
The tutorial actually working!
How to tell Cmake about Qt installation dir without changing PATH?
The reason your export CMAKE_PREFIX_PATH=...
didn't work is that you passed the bin
subdirectory instead of the installation prefix, as @vre already pointed out in the comments.
Alternatively, you can use -DQt5_ROOT=/Path/To/QtInstallationFolder/5.12.5/clang_64
. I personally prefer to use these kind of package specific variables because in CI build scripts you can easily put them on separate lines which then don't become too long.
Related Topics
What Occurs When a File Is 'Source'-D in Unix/Linux Context
How to Extract a Single Chunk of Bytes from Within a File
How to Get a List of All Valid Ip Addresses in a Local Network
How to Get the Last Word in Each Line with Bash
Git: Can't Push (Unpacker Error) Related to Permission Issues
Tcp_Tw_Reuse VS Tcp_Tw_Recycle:Which to Use (Or Both)
How to Create Threads Without System Calls in Linux X86 Gas Assembly
How to Show Line Number When Executing Bash Script
How to Find Out Mount/Partition a Directory or File Is On? (Linux Server)
How to Get the Contents of a Webpage in a Shell Variable
Centos Through a Vm - No Urls in Mirrorlist
Linux Cross-Compilation for Arm Architecture
Get Final Url After Curl Is Redirected
Not Authorized for Query on Admin.System.Namespaces on Mongodb
Error: Service "Xxx" Uses an Undefined Network "Xxx"
Application 'Appname' Failed to Start (Port 8080 Not Available) on Open Shift Node App