2

I have a C++ header file which has the following lines:

#include <QXmlSimpleReader> #include <QXmlDefaultHandler> 

and my cmake has the following lines:

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

When running CMake I get the following error message:

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

What am I doing wrong?

1
  • 2
    Can you please post the whole content of your cmake? What is your version of cmake? Commented Jul 22, 2016 at 17:37

2 Answers 2

2

For some reason it do not adds to project include dirs.

Add this one to your cmake

INCLUDE_DIRECTORIES( ${Qt5Xml_INCLUDE_DIRS} ) 
Sign up to request clarification or add additional context in comments.

Comments

1

I guess you forgot to link against Qt5xml. A working example from the documentation for cmake 2.8.11 and later, modified to link against 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) 

9 Comments

He have compiling issue, not linking
target_link_libraries manages include paths in modern cmake: if it has not been called, include paths will be missing too -> compiling issue
Wow, never heard about this feature. Find package could update include dirs on the other hand. Any link to read? Could not found any mentions in cmake docs.
I can't find where I saw it in the doc, but the Qt cmake packages declare imported targets populated with the lib paths AND the include paths. You see how the imported target is created in a Qt installation in <qt_root_dir>/lib/cmake/Qt5Core/Qt5CoreConfig.cmake: search for a call to add_library. Note that you can generate such a file by installing exports.
I got it: see this link. And I used it in a project, so I can confirm you that way is really working ^^
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.