0

I have already seen a lot of questions about this topic, but none of them have the same problem as i do. As i have seen, this error occurs when there's some problem in the funcion declaration or initialization, but both of mine have everything correctly defined and initialized.

I have the definitions correctly done in the Piece.h file and the proper initializations with the ClassName in the cpp file.

this is my Piece.h:

#pragma once

#include <SFML/Graphics.hpp>;

using namespace sf;

class Piece
{

public:
    static Sprite blackKingTexture;
    static Sprite whiteKingTexture;
    static Sprite blackKnightTexture;
    static Sprite whiteKnightTexture;
    static Sprite blackRookTexture;
    static Sprite whiteRookTexture;
    static Sprite blackBishopTexture;
    static Sprite whiteBishopTexture;
    static Sprite whiteQueenTexture;
    static Sprite blackQueenTexture;
    static Sprite whitePawnTexture;
    static Sprite blackPawnTexture;


    static uint8_t white;
    static uint8_t black;
    static uint8_t  queen;
    static uint8_t king;
    static uint8_t bishop;
    static uint8_t knight;
    static uint8_t rook;
    static uint8_t pawn;

    static void init();
    static void loadImages();
    static void loadTypes();
};

This is my Piece.cpp:

#include "Piece.h"

Sprite Piece::blackKingTexture = Sprite();
Sprite Piece::whiteKingTexture;
Sprite Piece::blackKnightTexture;
Sprite Piece::whiteKnightTexture;
Sprite Piece::blackRookTexture;
Sprite Piece::whiteRookTexture;
Sprite Piece::blackBishopTexture;
Sprite Piece::whiteBishopTexture;
Sprite Piece::whiteQueenTexture;
Sprite Piece::blackQueenTexture;
Sprite Piece::whitePawnTexture;
Sprite Piece::blackPawnTexture;

uint8_t Piece::white;
uint8_t Piece::black;
uint8_t Piece::queen;
uint8_t Piece::king;
uint8_t Piece::bishop;
uint8_t Piece::knight;
uint8_t Piece::rook;
uint8_t Piece::pawn;

void Piece::init() {
    loadImages();
    loadTypes();
}

void Piece::loadImages() {
    Texture texture;

    texture.loadFromFile("graphics/BlackKing.png");
    blackKingTexture = Sprite(texture);

    texture.loadFromFile("graphics/WhiteKing.png");
    whiteKingTexture.setTexture(texture);

    texture.loadFromFile("graphics/BlackKnight.png");
    blackKnightTexture = Sprite(texture);

    texture.loadFromFile("graphics/WhiteKnight.png");
    whiteKnightTexture = Sprite(texture);

    texture.loadFromFile("graphics/BlackRook.png");
    blackRookTexture = Sprite(texture);

    texture.loadFromFile("graphics/WhiteRook.png");
    whiteKingTexture = Sprite(texture);

    texture.loadFromFile("graphics/BlackBishop.png");
    blackBishopTexture = Sprite(texture);

    texture.loadFromFile("graphics/WhiteBishop.png");
    whiteBishopTexture = Sprite(texture);

    texture.loadFromFile("graphics/BlackQueen.png");
    blackQueenTexture = Sprite(texture);

    texture.loadFromFile("graphics/WhiteQueen.png");
    whiteQueenTexture = Sprite(texture);

    texture.loadFromFile("graphics/BlackPawn.png");
    blackPawnTexture = Sprite(texture);

    texture.loadFromFile("graphics/WhitePawn.png");
    whitePawnTexture = Sprite(texture);
}


void Piece::loadTypes() {
    //first 3 bits for type
    pawn = 1;
    rook = 2;
    knight = 4;
    bishop = 8;
    queen = 16;
    king = 32;

    //last 2 bits for color
    white = 64;
    black = 128;

}

Then i just call the Piece::init() in the Board.cpp file like this. it was supposed to work...

#include <SFML/Graphics.hpp>;
#include <string>
#include <cctype> 
#include <iostream>
#include "Piece.h"
using namespace sf;

class Board {
public:
   char board[8][8];

   Board(const std::string& fen) {
       Piece::init();
       loadBoardFromFen(fen);
   }
...

The error is:

Error   LNK2019 unresolved external symbol "public: static void __cdecl Piece::init(void)" (?init@Piece@@SAXXZ) referenced in function "public: __thiscall Board::Board(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Board@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

Build started...
1>------ Build started: Project: Basic Chess Game, Configuration: Debug Win32 ------
1>Basic Chess Game.obj : error LNK2019: unresolved external symbol "public: static void __cdecl Piece::init(void)" (?init@Piece@@SAXXZ) referenced in function "public: __thiscall Board::Board(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Board@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1 : fatal error LNK1120: 1 unresolved externals
1>Done building project "Basic Chess Game.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

0 Answers0