错误LNK2019未解析的外部符号 - 类库问题?

时间:2014-03-11 01:51:36

标签: c++ visual-studio-2013 lnk2019

我有一个包含2个项目的解决方案。 (VS2013)

一个项目是带有XAML项目的Direct3D,另一个是静态类库。

我已经设置了项目依赖项。

enter image description here

我想知道未解决的外部符号是否与此有关。

以下是我遇到的错误......我发现很难理解其含义

Error   1   error LNK2019: unresolved external symbol "public: __thiscall Game::Model::Input::Keyboard::Keyboard(void)" (??0Keyboard@Input@Model@Game@@QAE@XZ) referenced in function "public: __cdecl Game::App::App(void)" (??0App@Game@@Q$AAA@XZ)    C:\Users\James\Documents\Visual Studio 2013\Projects\Games\Jimmy\Game\App.xaml.obj  Game
Error   2   error LNK2019: unresolved external symbol "public: __thiscall Game::Model::Entities::Player::Player(void)" (??0Player@Entities@Model@Game@@QAE@XZ) referenced in function "public: void __thiscall Game::PlayerRenderer::InstantiateDependantObjects(void)" (?InstantiateDependantObjects@PlayerRenderer@Game@@QAEXXZ)  C:\Users\James\Documents\Visual Studio 2013\Projects\Games\Jimmy\Game\PlayerRenderer.obj    Game
Error   3   error LNK1120: 2 unresolved externals   C:\Users\James\Documents\Visual Studio 2013\Projects\Games\Jimmy\Debug\Game\Game.exe    1   1   Game

这是它正在努力解决的代码的一部分:

示范项目

模型\实体\ Keyboard.h

#pragma once

namespace Game
{
    namespace Model
    {
        namespace Input
        {
            class Keyboard
            {
            public:
                Keyboard();

                bool Up;
                bool Down;
                bool Left;
                bool Right;
                bool Space;
                bool Escape;
            };
        }
    }
}

模型\实体\ Keyboard.cpp

#include "pch.h"

#include "Entities\Keyboard.h"

using namespace Game::Model::Input;

Keyboard::Keyboard()
:   Up( FALSE ),
    Down( FALSE ),
    Left( FALSE ),
    Right( FALSE ),
    Space( FALSE ),
    Escape( FALSE )
{}

游戏项目

游戏\ App.xaml.h

#pragma once

...
#include "..\Model\Entities\Keyboard.h"    
...

using namespace Game::Model::Input;

namespace Game
{
    ref class App sealed
    {
    public:
        ...    
    private:
        ...         
            Keyboard* keyboard;    
            ...
    };
}

游戏\ App.xaml.cpp

App::App()
{
    InitializeComponent();
    keyboard = new Keyboard();
    Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
    Resuming += ref new EventHandler<Object^>( this, &App::OnResuming );
}

...

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

该对话框没有按照您的希望执行,您实际上并未链接静态库项目。它曾经在VS2010之前的旧VS版本中使用,现在它只设置构建顺序。

而是使用Project + Properties,Common Properties,References。单击Add New Reference按钮并勾选您的库项目。