尝试使用包含的Qt类库库构建项目时发生错误

时间:2019-05-18 15:04:00

标签: c++ qt

我已经使用Qt VS Tools为Visual Studio 2019创建了Qt类库。 我将此库也包含在我也使用Qt VS工具制作的Qt项目中, 但现在我的项目无法建立。

那是我项目的.pro文件:

# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Tools.
# ------------------------------------------------------

TEMPLATE = app
TARGET = JanturiolGameServer
DESTDIR = ./Win32/Debug
QT += core network gui widgets networkauth
CONFIG += debug
DEFINES += _UNICODE _ENABLE_EXTENDED_ALIGNED_STORAGE WIN64 QT_DLL QT_NETWORK_LIB QT_NETWORKAUTH_LIB QT_WIDGETS_LIB
INCLUDEPATH += ../../JanturiolLib \
    ./GeneratedFiles \
    . \
    ./GeneratedFiles/$(ConfigurationName)
LIBS += -L"../../JanturiolLib"
DEPENDPATH += .
MOC_DIR += ./GeneratedFiles/$(ConfigurationName)
OBJECTS_DIR += debug
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(JanturiolGameServer.pri)

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../JanturiolLib/Win32/release/ -lJanturiolLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../JanturiolLib/Win32/debug/ -lJanturiolLib
else:unix: LIBS += -L$$PWD/../JanturiolLib/Win32/ -lJanturiolLib

INCLUDEPATH += $$PWD/../JanturiolLib
DEPENDPATH += $$PWD/../JanturiolLib

那是我图书馆的.pro文件:

# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Tools.
# ------------------------------------------------------

TEMPLATE = lib
TARGET = JanturiolLib
DESTDIR = ./Win32/Release
QT += core xml network gui uitools widgets networkauth
CONFIG += release
DEFINES += _UNICODE _ENABLE_EXTENDED_ALIGNED_STORAGE WIN64 QT_DLL QT_NETWORK_LIB QT_NETWORKAUTH_LIB QT_UITOOLS_LIB QT_WIDGETS_LIB QT_XML_LIB JANTURIOLLIB_LIB
INCLUDEPATH += ./GeneratedFiles \
    . \
    ./GeneratedFiles/$(ConfigurationName)
DEPENDPATH += .
MOC_DIR += ./GeneratedFiles/$(ConfigurationName)
OBJECTS_DIR += release
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(JanturiolLib.pri)

那是PlayerChracter.h:

#pragma once
#include "BaseCharacter.h"
#include <string>

enum CharacterClass{warrior, mage, ranger};

//position
struct Pos
{
    int xPos;
    int yPos;
};

class PlayerCharacter : public BaseCharacter
{
public:
    PlayerCharacter(std::string charName);
    virtual ~PlayerCharacter();

protected:
    std::string name;
    Pos position;
};

那是PlayerChracter.cpp:

    #include "PlayerCharacter.h"

   PlayerCharacter::PlayerCharacter(std::string charName)
    {
        name = charName;
        position.xPos = 0;
        position.yPos = 0;
    }


    PlayerCharacter::~PlayerCharacter()
    {
    }

如果我尝试通过Visual Studio构建项目,则会收到此错误:

1> ------开始构建:项目:JanturiolGameServer,配置:调试Win32 ------ 1> JanturiolGameServer.cpp 1> JanturiolGameServer.obj:错误LNK2019:未解析的外部符号“公共:__thiscall PlayerCharacter :: PlayerCharacter(class std :: basic_string,class std :: allocator>)”(?? 0PlayerCharacter @@ QAE @ V?$ basic_string @ DU? $ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ Z中的$ allocator @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ Z?)(?ProcessDatagram @ JanturiolGameServer @@ AAEXAAVQByteArray @@@ Z) 1> C:\ Users \ GKR \ source \ repos \ JanturiolGameServer \ Win32 \ Debug \ JanturiolGameServer.exe:致命错误LNK1120:1个未解决的外部组件 1>完成的构建项目“ JanturiolGameServer.vcxproj”-失败。 ===========构建:0成功,1失败,0最新,跳过0 ==========

如果我尝试通过Qt创建者4. 9. 0构建项目,则会收到此错误:

https://monosnap.com/file/f9XQ1s0VQpfx8e6PXYtkaNl2X409ra

这是.lib文件的路径:

https://monosnap.com/file/oeaH3vuXMIYQ7aLY3vcWd6qk0QqOOy

1 个答案:

答案 0 :(得分:0)

在项目文件中,您已经设置了WIN64,但是编译器的输出状态为Debug Win32。

可能的原因,请参见“ https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2019?view=vs-2019”中的“尝试将64位库链接到32位代码或将32位库链接到64位代码”