2016-07-22 101 views
1

我有具有如下的C++頭文件:CMake的找不到QXmlSimpleReader

#include <QXmlSimpleReader> 
#include <QXmlDefaultHandler> 

和我的CMake的有下面幾行:

find_package(Qt5Core REQUIRED) 
find_package(Qt5Widgets REQUIRED) 
find_package(Qt5Xml REQUIRED) 

當運行CMake的我收到以下錯誤信息:

QXmlSimpleReader: No such file or directory 
#include <QXmlSimpleReader> 

我在做什麼錯?

+2

能否請您發表您的CMake的全部內容?你的cmake版本是什麼? – wasthishelpful

回答

1

我想你忘了鏈接到Qt5xml。從documentation爲cmake的2.8.11及更高版本,修改,針對Qt5Xml鏈接工作的示例:

cmake_minimum_required(VERSION 2.8.11) 

project(testproject) 

# Find includes in corresponding build directories 
set(CMAKE_INCLUDE_CURRENT_DIR ON) 
# Instruct CMake to run moc automatically when needed. 
set(CMAKE_AUTOMOC ON) 

# Find the QtWidgets library 
find_package(Qt5Xml) 

# Tell CMake to create the helloworld executable 
add_executable(helloworld WIN32 main.cpp) 

# Use the Widgets module from Qt 5. 
target_link_libraries(helloworld Qt5::Xml) 
+0

他有編譯問題,沒有鏈接 – Ation

+0

target_link_libraries在現代cmake中管理包含路徑:如果沒有被調用,include路徑也會丟失 - >編譯問題 – wasthishelpful

+0

哇,從來沒有聽說過這個功能。另一方面,查找包可能會更新包括dirs。任何鏈接閱讀?在cmake文檔中找不到任何提及。 – Ation

1

出於某種原因,它不添加到項目的include目錄。

添加這樣一來你的cmake

INCLUDE_DIRECTORIES(${Qt5Xml_INCLUDE_DIRS})