我正在尝试构建一个使用QT 5.5库的项目。要创建CMake文件,我使用cmake-gui并链接到库。默认情况下,程序将项目链接到QT 4.X的文件和目录,同时查找相同的文件和目录。 QT 5.5,我注意到其中一些不存在。 (按照印刷品)
可以看到这里有与QT 4.X和QT 5.5链接的文件
虽然您可以构建文件,但尝试使用make install命令会显示如下所示的错误。我认为这些错误正是因为缺少QT 4.X文件替换的QT 5.5档案而发生的。
这是我试图解决的错误
在这里,我开始看到必须以一种方式将目录链接到丢失的文件,这样就不再存在这种错误了.QT
我试图手动更改生成文件的包含目录,但是考虑到生成的错误数量,它似乎不可行。有什么方法可以替换" QT 5.5版本中缺少哪些文件?
这是用于此项目的CMakeLists.txt文件:
project(PacpusSensors)
cmake_minimum_required(VERSION 2.8)
# ========================================
# PacpusSensors version
# ========================================
set(PacpusSensors_MAJOR_VERSION 0)
set(PacpusSensors_MINOR_VERSION 1)
set(PacpusSensors_PATCH_VERSION 1)
set(PacpusSensors_VERSION
"${PacpusSensors_MAJOR_VERSION}.${PacpusSensors_MINOR_VERSION}.${PacpusSensors_PATCH_VERSION}")
# ========================================
# Configure CMake
# ========================================
set(PACPUS_ROOT "/home/marvsdd/PACPUS/export")
if(NOT ${PACPUS_ROOT} STREQUAL "")
set(CMAKE_MODULE_PATH ${PACPUS_ROOT}/cmake)
string (REPLACE "\\" "/" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
message (STATUS "setting CMAKE_MODULE_PATH to: " ${CMAKE_MODULE_PATH})
elseif( NOT $ENV{PACPUS_ROOT} STREQUAL "")
set(PACPUS_ROOT $ENV{PACPUS_ROOT})
set(CMAKE_MODULE_PATH $ENV{PACPUS_ROOT}/cmake)
string (REPLACE "\\" "/" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
message (STATUS "setting CMAKE_MODULE_PATH to: " ${CMAKE_MODULE_PATH})
message (STATUS "PACPUS_ROOT is: " ${PACPUS_ROOT})
else()
message (FATAL_ERROR "Environment variable PACPUS_ROOT not set, please define it in your operating system or pass it as argument to the cmake command")
endif()
include(${CMAKE_MODULE_PATH}/PacpusUtilities.cmake)
include(${CMAKE_MODULE_PATH}/PacpusConfiguration.cmake)
include(${CMAKE_MODULE_PATH}/PacpusDependencies.cmake)
include(${CMAKE_MODULE_PATH}/PacpusPlatforms.cmake)
# ========================================
# Pre-configuration of the compiler
# ========================================
find_package(Pacpus REQUIRED)
# Includes directories
if(PACPUS_FOUND)
include_directories(
${PACPUS_DEPENDENCIES_INC}
${PACPUS_INCLUDE_DIR}
)
# Compiler flags coming from PacpusDependencies and PacpusPlatforms
add_definitions(${PACPUS_DEFINITIONS})
endif(PACPUS_FOUND)
# ========================================
# Find dependencies
# ========================================
find_package(Qt4 REQUIRED)
if(QT4_FOUND)
set(QT_USE_QTNETWORK TRUE)
set(QT_USE_QTOPENGL TRUE)
set(QT_USE_QTXML TRUE)
include(${QT_USE_FILE})
add_definitions( ${QT_DEFINITIONS} )
add_definitions( -DQT_PLUGIN )
endif(QT4_FOUND)
include_directories(
${PACPUS_DEPENDENCIES_INC}
${PACPUS_INCLUDE_DIR}
${PACPUS_INCLUDE_HINT}
${PACPUS_INCLUDE_HINT}/Pacpus
./PACPUS/include
)
# ========================================
# Build the PacpusSensors' modules
# ========================================
add_subdirectory(PacpusSocket)
add_subdirectory(Sick)
# ========================================
# Summary
# ========================================
pacpus_info("")
pacpus_info("=====================================================================")
pacpus_info("Configuration for PacpusSensors ${PacpusSensors_VERSION}")
pacpus_info("=====================================================================")
pacpus_info("")
pacpus_info(" Platform:")
pacpus_info(" Host:" ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR})
if(CMAKE_CROSS_COMPILING)
pacpus_info(" Target:" ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR})
endif()
pacpus_info(" CMake:" ${CMAKE_VERSION})
pacpus_info(" CMake generator:" ${CMAKE_GENERATOR})
pacpus_info(" CMake build tool:" ${CMAKE_BUILD_TOOL})
if(MSVC)
pacpus_info(" MSVC:" ${MSVC_VERSION})
else()
pacpus_info(" Configuration:" ${CMAKE_BUILD_TYPE})
endif()
pacpus_info("")
pacpus_info(" Compiler:")
pacpus_info(" C++ Compiler:" ${CMAKE_CXX_COMPILER})
pacpus_info(" C++ flags (release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
pacpus_info(" C++ flags (debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
pacpus_info("")
pacpus_info(" Pacpus:")
pacpus_info(" PacpusFramework path:" ${PACPUS_ROOT})
pacpus_info(" Log4cxx logging enabled:" ${PACPUS_USE_LOG})
pacpus_info("")
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(WARNING "The source directory is the same as build directory. \"make clean\" may damage the source tree")
endif()
答案 0 :(得分:0)
我看到的第一件事就是Qt4和Qt5在这里混合了。如果您已安装两者,那就没关系,但一定要使用正确的。我假设你想要Qt5。
链接到Qt5的一个简单示例如下所示:
find_package(Qt5 REQUIRED Network OpenGL Xml) #Qt5Core is implicit
target_link_libraries(MyApplication Qt5::Network Qt5::OpenGL Qt5::Xml)
您不需要if(Qt5_FOUND)
,因为软件包是REQUIRED
,这意味着如果找不到QT,它将失败并显示错误。
在您的CMakeLists.txt中,您没有定义任何目标。您通常会使用add_executable
,add_library
或add_custom_target
cmake函数执行此操作。这意味着目标可能在您的子目录中定义。在子目录中找到适当的CMakeLists.txt并在那里使用target_link_libraries
命令。此命令将添加正确的标题并为您执行适当的链接。
如果Qt只是标题,那么使用全局include_directories()
和add_definitions()
会起作用,但由于您需要将应用程序链接到Qt,因此您需要实际使用{{ 1}}在你的解决方案中更深层次。
有关详细信息,请查看Qt's documentation