Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 在visual studio中生成Qt项目时发生LNK2019错误_Visual Studio_Qt_Cmake_Linker - Fatal编程技术网

Visual studio 在visual studio中生成Qt项目时发生LNK2019错误

Visual studio 在visual studio中生成Qt项目时发生LNK2019错误,visual-studio,qt,cmake,linker,Visual Studio,Qt,Cmake,Linker,我使用CMake制作了一个VisualStudio项目,当我试图编译它时,我会遇到这些错误。这个错误似乎只与QDomDocument对象相关,我没有得到任何与其他Qt类相关的链接错误 Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QD

我使用CMake制作了一个VisualStudio项目,当我试图编译它时,我会遇到这些错误。这个错误似乎只与QDomDocument对象相关,我没有得到任何与其他Qt类相关的链接错误

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QDomNode::~QDomNode(void)" (__imp_??1QDomNode@@QEAA@XZ) referenced in function "private: void __cdecl Graph::readFromFile(class QString)" (?readFromFile@Graph@@AEAAXVQString@@@Z)    Gps_test    C:\Users\Cristi\Desktop\an2 sem 2\QT\gps_test1\build\graph.obj  1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class QDomNodeList __cdecl QDomNode::childNodes(void)const " (__imp_?childNodes@QDomNode@@QEBA?AVQDomNodeList@@XZ) referenced in function "private: void __cdecl Graph::readFromFile(class QString)" (?readFromFile@Graph@@AEAAXVQString@@@Z) Gps_test    C:\Users\Cristi\Desktop\an2 sem 2\QT\gps_test1\build\graph.obj  1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: bool __cdecl QDomDocument::setContent(class QIODevice *,class QString *,int *,int *)" (__imp_?setContent@QDomDocument@@QEAA_NPEAVQIODevice@@PEAVQString@@PEAH2@Z) referenced in function "private: void __cdecl Graph::readFromFile(class QString)" (?readFromFile@Graph@@AEAAXVQString@@@Z)  Gps_test    C:\Users\Cristi\Desktop\an2 sem 2\QT\gps_test1\build\graph.obj  1   
这是源文件的我的CMake文件:

# Defines the minimum CMake version required for the CMakeLists.txt file
# to be correctly interpreted. Older versions of CMake may not contain
# all the features to "understand" this file.
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)

# Defines the name and language the project will be using.
project(Gps_test LANGUAGES CXX)

# Set the path to the Qt5 installation's CMake instructions.
set(Qt5_DIR "D:/qt/5.10.1/msvc2017_64/lib/cmake/Qt5")

# Automatically add the current source and build directories to the
# include path.
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Automatically create Qt5 MOCs at compile time.
set(CMAKE_AUTOMOC ON)

# Automatically create Qt5 UICs at compile time.
set(CMAKE_AUTOUIC ON)

# Include Qt5 and its widgets.
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)

# Add to PROJECT_SOURCES variable all the filenames inside
# ${CMAKE_CURRENT_SOURCE_DIR} which respect the given pattern.
file(GLOB PROJECT_SOURCES "*.cpp")

# Instruct CMake to create an executable based on all the .cpp
# sources of the project. You may, for example, create multiple
# executables based on different source files, inside the same
# project.
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})

# Specify libraries or flags to use when linking a given target. 
target_link_libraries(${PROJECT_NAME} 
    PUBLIC 
    Qt5::Core
    Qt5::Gui
    Qt5::Widgets)

有人知道我怎么解决这个问题吗?谢谢。

这些是
Xml
组件的一部分。试试这个:

find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Xml)
...
target_link_libraries(${PROJECT_NAME} 
PUBLIC 
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Xml
)

谢谢,修好了