Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Getting a LNK2019 error  (Read 1696 times)

0 Members and 1 Guest are viewing this topic.

Ausche

  • Newbie
  • *
  • Posts: 19
    • View Profile
[SOLVED]Getting a LNK2019 error
« on: November 04, 2015, 02:57:22 am »
I've been working on this player class all day and now I get this error when I build everything after I passed all of the debugging. It's my first time really messing with headers/classes and SFML. Also I'm new to video game programming so I still lack a lot of the intuition.

These are my exact two errors-

19   error LNK2019: unresolved external symbol "public: bool __thiscall Player::load_player(void)" (?load_player@Player@@QAE_NXZ) referenced in function _main   C:\Users\OverLordSupreme\Documents\Visual Studio 2012\Projects\Playgrounds\Playgrounds\main.obj   DIM

Error   20   error LNK1120: 1 unresolved externals   C:\Users\OverLordSupreme\Documents\Visual Studio 2012\Projects\Playgrounds\Debug\DIM.exe   DIM

Forewarning- I commented out some code for various reasons, so everything not commented is how I intend for this program to work.

The main file:
#include <SFML/Graphics.hpp>
#include <math.h>
#include <iostream>
#include "tile_class.cpp"
#include "player.h"

using namespace sf;

int main()
{
    const int WINDOW_WIDTH = 512;
        const int WINDOW_HEIGHT = 256;
       

        RenderWindow window(VideoMode(512, 256), "DIM");
        window.setKeyRepeatEnabled(false);

        const int level[] =
        {
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        };

        TileMap map;
        if (!map.load("grass.png", Vector2u(32,32), level,16, 8))
        {return -1;}
       
        Player Hero;
        Hero.setPlayer(100,100,0,0,0,0,1,Vector2i(256,128));
        Hero.load_player();

    RectangleShape upper_border(Vector2f(WINDOW_WIDTH, 5));
        upper_border.setPosition(0,-5);

        RectangleShape lower_border(Vector2f(WINDOW_WIDTH, 5));
        lower_border.setPosition(0,WINDOW_HEIGHT);

        RectangleShape left_border(Vector2f(5, WINDOW_HEIGHT));
        left_border.setPosition(-5,0);

        RectangleShape right_border(Vector2f(5, WINDOW_HEIGHT));
        right_border.setPosition(WINDOW_WIDTH,0);

        while (window.isOpen())
    {
                FloatRect boundingBox = Hero.getGlobalBounds();
                FloatRect left_box = left_border.getGlobalBounds();
                FloatRect right_box = right_border.getGlobalBounds();
                FloatRect upper_box = upper_border.getGlobalBounds();
                FloatRect lower_box = lower_border.getGlobalBounds();

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
                       
                }

                double move_variable=.035*Hero.getSpeed();

                if (Keyboard::isKeyPressed(Keyboard::Left) && !boundingBox.intersects(left_box))
                {Hero.move(-move_variable,0);}

                if (Keyboard::isKeyPressed(Keyboard::Right) && !boundingBox.intersects(right_box))
                {Hero.move(move_variable,0);}
               
                if (Keyboard::isKeyPressed(Keyboard::Up) && !boundingBox.intersects(upper_box))
                {Hero.move(0,-move_variable);}

                if(Keyboard::isKeyPressed(Keyboard::Down) && !boundingBox.intersects(lower_box))
                {Hero.move(0,move_variable);}

                window.clear(Color::White);    
                window.draw(map);
                window.draw(left_border);
                window.draw(right_border);
                window.draw(upper_border);
                window.draw(lower_border);
                window.draw(Hero);
        window.display();
    }

    return 0;
}
 

The Player hpp file
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics.hpp>

using namespace sf;

class Player: public Sprite, public Texture
{
public:
        Player();
        void setPlayer(int current_health, int health_pool, int current_armor, int current_weapon, int weapon_upgrade, int inventory, int speed, Vector2i position);
        void setCurrentHealth(int);
        void setHealPool(int);
        void setCurrentArmor(int);
        void setCurrentWeapon(int);
        void setWeaponUpgrade(int);
        void setInventory(int);
        void setSpeed(int);
        void setPosition(Vector2i);

        int getCurrentHealth();
        int getHealPool();
        int getCurrentArmor();
        int getCurrentWeapon();
        int getWeaponUpgrade();
        int getInventory();
        int getSpeed();
        Vector2i getPosition();

        void playermove(Vector2i);
        bool load_player();

private:
        int player_states[7];
        Vector2i player_position;
        Sprite playerSprite;

        int current_health;
        int health_pool;
        int current_armor;
        int current_weapon;
        int weapon_upgrade;
        int inventory;
        int speed;
        Vector2i position;

};
 

And finally the player cpp file
#include <SFML/Graphics.hpp>
#include "player.h"
#include <iostream>

using namespace sf;
using namespace std;

Player::Player()
{
}
void Player::setPlayer(int current_health, int health_pool, int current_armor, int current_weapon, int weapon_upgrade, int inventory, int speed, Vector2i position)
{
        setCurrentHealth(current_health);
        setHealPool(health_pool);
        setCurrentArmor(current_armor);
        setCurrentArmor(current_armor);
        setCurrentWeapon(current_weapon);
        setWeaponUpgrade(weapon_upgrade);
        setInventory(inventory);
        setSpeed(speed);
        setPosition(position);
}

void Player::setCurrentHealth(int current_health)
        {player_states[0]=current_health;}

void Player::setHealPool(int health_pool)
        {player_states[1]=health_pool;}

void Player::setCurrentArmor(int current_armor)
        {player_states[2]=current_armor;}

void Player::setCurrentWeapon(int current_weapon)
        {player_states[3]=current_weapon;}

void Player::setWeaponUpgrade(int weapon_upgrade)
        {player_states[4]=weapon_upgrade;}

void Player::setInventory(int inventory)
        {player_states[5]=inventory;}

void Player::setSpeed(int speed)
        {player_states[6]=speed;}

void Player::setPosition(Vector2i position)
        {player_position=position;}

int Player::getCurrentHealth()
        {int current_health=player_states[0];
        return current_health;}

int Player::getHealPool()
        {int health_pool=player_states[1];
        return health_pool;}

int Player::getCurrentArmor()
        {int current_armor=player_states[2];
        return current_armor;}

int Player::getCurrentWeapon()
        {int current_weapon=player_states[3];
        return current_weapon;}

int Player::getWeaponUpgrade()
        {int weapon_upgrade=player_states[4];
        return weapon_upgrade;}

int Player::getInventory()
        {int inventory=player_states[5];
        return inventory;}

int Player::getSpeed()
        {int speed=player_states[6];
        return speed;}

Vector2i Player::getPosition()
        {Vector2i position=player_position;
        return position;}

bool load_player()
{
        Texture player_texture;
        if (!player_texture.loadFromFile("face_right"))
        {
                cerr<< "Texture error" << endl;
                return false;
        }
        Sprite player;
        player.setTexture(player_texture);
        return true;
}
 

Any help with this would be awesome! I did try to rename the whole project from "Playgrounds" to "DIM", I feel like that might be helpful to know.

Also while I'm posting this, if anyone could critique my coding that'd be great. Like I said I'm new to this stuff including C++ so I don't know if there's any more ideal ways to go about what I'm doing.
« Last Edit: November 04, 2015, 10:41:47 pm by Ausche »
Struggling to make a game happen!

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Getting a LNK2019 error
« Reply #1 on: November 04, 2015, 05:41:12 am »
Check the implementation of your load_player function in your Player class. Compare it to another function implementation in the same class. See the difference? :)

By the way, the error message is telling you where to look: "Player::load_player()"

Ausche

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Getting a LNK2019 error
« Reply #2 on: November 04, 2015, 07:38:44 pm »
Check the implementation of your load_player function in your Player class. Compare it to another function implementation in the same class. See the difference? :)

By the way, the error message is telling you where to look: "Player::load_player()"

Ah I see, thank you. Silly mistakes!
Struggling to make a game happen!