I am getting the error:
Error LNK2019 unresolved external symbol "public: struct DirectX::SimpleMath::Vector2 __thiscall Bird::getScreenPos(void)" (?getScreenPos@Bird@@QAE?AUVector2@SimpleMath@DirectX@@XZ) referenced in function "private: void __thiscall Game::Render(void)" (?Render@Game@@AAEXXZ)
When I run my code. I don't know what the problem is, and I was hoping someone could help me here is the code to the class in which the method I am calling is:
//
//Bird.h
//
#pragma once
class Bird
{
private:
DirectX::SimpleMath::Vector2 screenPos;
int yVelocity;
const int gravity = 3;
public:
Bird();
~Bird();
void Flap();
void Update();
inline void Bird::setScreenPos(DirectX::SimpleMath::Vector2 newPos);
inline DirectX::SimpleMath::Vector2 Bird::getScreenPos();
inline void setX(float newX);
inline void setY(float newY);
};
//
//Bird.cpp
//
#include "pch.h"
#include "Bird.h"
Bird::Bird()
{
screenPos.y = 500;
screenPos.x = 100;
yVelocity = 0;
}
Bird::~Bird()
{
}
void Bird::Flap()
{
yVelocity = 50;
}
void Bird::Update()
{
yVelocity -= gravity;
screenPos.y += yVelocity;
}
inline DirectX::SimpleMath::Vector2 Bird::getScreenPos()
{
return screenPos;
}
inline void Bird::setX(float newX)
{
screenPos.x = newX;
}
inline void Bird::setY(float newY)
{
screenPos.y = newY;
}
inline void Bird::setScreenPos(DirectX::SimpleMath::Vector2 newPos)
{
if (screenPos.y < 0)
screenPos = newPos;
}
And the code where I initialize the objects is at the bottom of this block:
//
// Game.h
//
#pragma once
#include "StepTimer.h"
#include "Bird.h"
// A basic game implementation that creates a D3D11 device and
// provides a game loop.
class Game
{
public:
Game() noexcept;
~Game() = default;
Game(Game&&) = default;
Game& operator= (Game&&) = default;
Game(Game const&) = delete;
Game& operator= (Game const&) = delete;
// Initialization and management
void Initialize(HWND window, int width, int height);
// Basic game loop
void Tick();
// Messages
void OnActivated();
void OnDeactivated();
void OnSuspending();
void OnResuming();
void OnWindowSizeChanged(int width, int height);
// Properties
void GetDefaultSize( int& width, int& height ) const noexcept;
private:
void Update(DX::StepTimer const& timer);
void Render();
void Clear();
void Present();
void CreateDevice();
void CreateResources();
void OnDeviceLost();
// Device resources.
HWND m_window;
int m_outputWidth;
int m_outputHeight;
D3D_FEATURE_LEVEL m_featureLevel;
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
// Rendering loop timer.
DX::StepTimer m_timer;
//texture
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_texture;
std::unique_ptr<DirectX::SpriteBatch> m_spriteBatch;
DirectX::SimpleMath::Vector2 m_origin;
Bird* bird;
};
The actual function is called here in Game.cpp:
bird->setX(backBufferWidth / 2.f);
Thank you!
Error LNK2019
which means a compiler found a declaration ofVector2
provided by your library, but linker couldn't find a definition of it. Check how you added your library in your IDE. In general libraries have aninclude
folder for compiler and alib
folder for linker. Both should be specified though somewhere in your project's settings – Alexey Larionov