【发布时间】:2018-04-07 13:19:27
【问题描述】:
我使用 CMake 制作了一个 Visual Studio 项目,当我尝试编译它时,我得到了这些错误。该错误似乎仅与 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)
有人知道我该如何解决这个问题吗?谢谢。
【问题讨论】:
标签: visual-studio qt cmake linker