使用CMakeLists.txt设置Qt5 -文件未发现错误
Setting up Qt5 with CMakeLists.txt - file not found errors
我正在尝试在OS x上设置一个cmake项目。我几乎已经编译了它,但我在获得Qt5工作时遇到了一点麻烦。
当我尝试编译时,我得到:
fatal error: 'QtCore/QDir' file not found
fatal error: 'QtCore/QDate' file not found
当我检查我的代码时,IDE用红色突出显示QtCore和QtWidgets,表明没有找到它们。
你们知道我错过了什么吗?
我的CMakeLists.txt如下:
cmake_minimum_required(VERSION 3.3)
project(miniLogbook)
subdirs(sources headers lib other)
#For a basic project, you should probably only need to edit these variables
#Base QT directory
set(QT_PATH "/Users/rwardrup/Qt")
#Build output path of your QT Creator project
set(QT_BIN "./ml_debug")
#QT Version used, e.g. Probably found in ${QT_PATH}
set(QT_VERSION "5.7")
#Libraries to link to
set(QT_LIBRARIES Qt5::Core Qt5::Widgets Qt5::Gui)
#Libraries required. Probably the same as above minus the '::'. find_package() will be called on these
set(QT_LIBRARIES_REQUIRED Qt5Core Qt5Widgets Qt5Gui)
#################################################################
#Pull needed header files generated by QT first
set(QT_GENERATED qtGenerated)
add_custom_target(${QT_GENERATED})
#Get all header files in the directory
file(GLOB QT_GEN_HEADERS ${QT_BIN}/*.h)
#Copy them to the project dir
foreach(QT_GEN_HEADERS ${QT_GEN_HEADERS})
add_custom_command(TARGET ${QT_GENERATED} PRE_BUILD COMMAND
${CMAKE_COMMAND} -E copy_if_different
${QT_GEN_HEADERS} ${CMAKE_SOURCE_DIR})
endforeach()
#Build tool paths
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_AR "/usr/bin/ar")
set(CMAKE_LINKER "/usr/bin/g++")
#find packages
foreach(QT_LIBRARIES_REQUIRED ${QT_LIBRARIES_REQUIRED})
find_package( ${QT_LIBRARIES_REQUIRED} REQUIRED )
endforeach()
file(GLOB QT_CPP_GENERATED ${QT_BIN}/*.cpp)
set(SOURCES sources/main.cpp sources/mainwindow.cpp headers/mainwindow.h ${QT_GEN_HEADERS} ${QT_CPP_GENERATED})
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.59.0 COMPONENTS filesystem)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(miniLogbook ${SOURCES})
add_dependencies(${PROJECT_NAME} ${QT_GENERATED})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${Boost_LIBRARIES})
endif()
你的foreach
循环有bug
在这两种情况下,都是用第一个元素覆盖要循环遍历的值列表。
它们应该按照以下模式阅读:
foreach(_loop_var ${list_of_values})
# do stuff with ${_loop_var}
endforeach(_loop_var)
我相信你所面临的问题只是CMake没有搜索所有你想要搜索的Qt5模块的症状。你可能需要重新检查CMake缓存和日志输出。
旁注:将系统组件的绝对路径硬编码到CMake文件中是非常糟糕的做法。这使得CMake(几乎)毫无用处。如果你不想给CMake很多命令行参数来指定特定的位置,请阅读工具链文件。
如果这个CMakeLists文件是来自某个地方的示例模板,我建议不要使用CMake相关建议的源代码
相关文章:
- 此代码编译良好,但文件未创建?请指出错误
- Android NDK 编译 LAME HAVE_MPGLIB > 'interface.h' 文件未找到
- 如何使用libav编写.mov文件,如果文件未正确完成,则可以播放
- C++ 生成文件未检测到 .h 文件中的更改
- CTest 项目目录.未发现任何测试
- 名称具有空格的文件未编译
- 链接器输入文件未使用,因为链接未完成,我无法获得.o
- 使用重定向命令从 stdin 读入的字符串"<"输入文件未正确附加
- 引入流时C++数据文件未正确读取?
- CSV文件未从缓冲区获取数据
- Visual Studio代码文件未输出
- Visual Studio 2017 单元测试与 C++ 和 C# 与未发现的C++测试
- 我的输出文件未显示解决方案
- Android CMake "致命错误: 'bits/libc-header-start.h' 文件未找到"
- SO文件未在Android Studio中使用CMake生成
- 为什么我的QTRPT项目文件未在QTCreator中运行
- 关于Visual Studio 2017中未发现错误的精致询问
- 此CMAKE错误意味着什么?我的变量设置为未发现
- 从电子项目运行的可执行文件未加载资源
- 使用CMakeLists.txt设置Qt5 -文件未发现错误