I am a student writing a project. I have created a program (here's the link to SVN: https://mysvn.ru/Ilya_Antonov/antonov_sem_prj). I use CMake to build it and generate the .sln project. But when run it in Visual Studio, there are some errors: the compiler can't open the files "drumswindow.h" and "mainwindow.h" (fatal error C1083). Please, take a look at my CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
project(MusicSimulator VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Multimedia REQUIRED)
add_executable(MusicSimulator
mainwindow.ui
mainwindow.cpp
mainwindow.h
main.cpp
drumswindow.ui
drumswindow.cpp
drumswindow.h
keyswindow.ui
keyswindow.cpp
keyswindow.h
images.qrc
drumres.qrc
keysres2.qrc
keysres3.qrc
keysres4.qrc
keysres5.qrc
keysres6.qrc
)
target_link_libraries(MusicSimulator Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Multimedia)
What have I done wrong here?
You don't include the current source dir and therefore the compiler doesn't find it. Either add the current source dir or use the correct include statements (#include "keyswindow.h" for example)
Related
I am using Qt 6.2.1 with cmake and I can't find a way to use Qt Charts.
The Qt Charts is installed under "C:\Qt\6.2.1\Src\qtcharts"
In my cmakelists.txt I've included the Qt Charts in find_package and target_link_libraries. That seemed to work on qt5 (found on other answers in StackOverflow) but don't work on qt6. (I've hidden the project sources files)
cmake_minimum_required(VERSION 3.5)
project(projectname VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG "/MDd")
find_package(QT NAMES Qt6 COMPONENTS Widgets Charts REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Xml Widgets REQUIRED)
set(PROJECT_SOURCES
...
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(projectname
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
add_executable(projectname
${PROJECT_SOURCES}
)
endif()
target_link_libraries(projectname PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Xml Qt6::Charts)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(projectname)
endif()
I get this error:
C:\Qt\6.2.1\msvc2019_64\lib\cmake\Qt6Core\Qt6CoreMacros.cmake:559: error: Target "projectname" links to target "Qt6::Charts" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? C:/Qt/6.2.1/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:523 (_qt_internal_create_executable) C:/Qt/6.2.1/msvc2019_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:847 (qt6_add_executable) CMakeLists.txt:78 (qt_add_executable)
SOLUTION (Thanks to #vre):
I had to select the Qt Charts under 6.2.1 and not under Qt in the online installer
Qt Online Installer
I am trying to make a project with subdirectories using cmake.
When using qmake this mechanism was built in Qt creator.
The project contains a shared library and a desktop app.
Below is the structure of the project and cmake I have:
Main cmake:
cmake_minimum_required (VERSION 3.5)
project(contractapp)
add_subdirectory(contract-core)
add_subdirectory(contract-desktop)
Desktop app cmake:
project(contract-desktop LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package( ...) calls below.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(contract-core REQUIRED)
set(PROJECT_SOURCES
main.cpp
MainWindow.cpp
MainWindow.h
MainWindow.ui
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(contract-desktop
${PROJECT_SOURCES}
)
else()
if(ANDROID)
add_library(contract-desktop SHARED
${PROJECT_SOURCES}
)
else()
add_executable(contract-desktop
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(contract-desktop PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
Shared library cmake:
cmake_minimum_required(VERSION 3.14)
project(contract-core LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
add_library(contract-core SHARED
contract-core_global.h
Person.cpp
Person.h
)
target_link_libraries(contract-core PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(contract-core PRIVATE CONTRACTCORE_LIBRARY)
My problem is that the desktop application does not see the library that I am making.
That library has to be copied to the same folder the application is in. Otherwise, each is in its own folder, and the application won't see it. Most likely you'd want to set the target folder for both binaries (the application and the library) to be some common build subfolder of both.
I'm trying to run the imageviewer example from this website https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html.
However, for some reason I don't seem to have QColorSpace.
I tried to include all of the possible libraries I thinnk I would need but still have no luck.
Is it my CMake file or do I need to somehow install QColorSpace?
cmake_minimum_required(VERSION 3.5)
project(SAT_Solver LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets PrintSupport OpenGL Core Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets PrintSupport OpenGL Core Gui REQUIRED)
if(ANDROID)
add_library(SAT_Solver SHARED
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
ScribbleArea.cpp
ScribbleArea.h
)
else()
add_executable(SAT_Solver
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
ScribbleArea.cpp
ScribbleArea.h
imageviewer.h
imageviewer.cpp
)
endif()
#qt5_add_resources(RC_SRC "resources/qml.qrc")
#qt5_add_resources(RC_SRC "/home/nalfredo/School/AutoSoftware/Project/QT/SAT_Solver/Resources.qrc")
target_link_libraries(SAT_Solver PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::PrintSupport
${QT_QTSVG_LIBRARY} Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Core Qt5::Gui)
I am trying to integrate my QT project to my CLION project.
In this case I am having problems with the CMAKE and QT integration.
The content of my CmakeList.txt is:
cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/")
find_package(Qt5Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui)
target_link_libraries(helloworld Qt5::Widgets)
But I am getting the following error:
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
Could someone help me?
Thank you
after some tries, I found the solution to my problem.
So I am posting my CMakeList.txt code in case you have the same problem.
cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/clang_64/lib/cmake")
find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui ui/input.ui)
target_link_libraries(BD2_PROYECTO_1 Qt5::Widgets)
I hope this will helpful for you.
I want to make a Qt Quick project using CMake with compiled qml files. I put my QML files into a separate qrc/rcc file in a cmake projekt:
qt5_add_binary_resources("res" "qml.qrc" DESTINATION "qml.rcc")
This works fine so far. Now I wanted to compile them. According to the documentation I only need to change
qt5_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)
to
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)
in a project. So I changed my CMakeLists.txt to
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources("QML_RESOURCE" "qml.qrc")
qt5_add_binary_resources("res" ${QML_RESOURCE} DESTINATION "qml.rcc")
But now I get
FAILED: qml.rcc cmd.exe /C "cd /D "D:\buildPath" && C:\Qt\5.12.3\msvc2017_64\bin\rcc.exe --binary --name res --output qml.rcc "D:/buildPath/main_qml.cpp" "D:/buildPath/qmlcache_loader.cpp""
RCC Parse Error: 'D:/buildPath/main_qml.cpp' Line: 1 Column: 1 [Start tag expected.] [2/4 30.3/sec] Automatic MOC for target PROJECT_NAME ninja: build stopped: subcommand failed.
17:10:39: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1. Error while building/deploying project PROJECT_NAME (kit: Desktop Qt 5.12.3 MSVC2017 64bit) When executing step "Build with CMake"
There isn't much information about Qt and CMake, so I don't know what to do about this. I hope someone can give me some advice.
The full working CMakeLists is
cmake_minimum_required(VERSION 3.1)
project(QtQuickCompiler LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" ${RESOURCES})
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
The full not working file is
cmake_minimum_required(VERSION 3.1)
project(QtQuickCompiler LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
qt5_add_binary_resources(qml ${RESOURCES} DESTINATION "qml.rcc")
add_executable(${PROJECT_NAME} "main.cpp")
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
This was created using the template projects provided by QtCreator.