1 Replies - 272 Views - Last Post: 05 November 2015 - 07:22 AM Rate Topic: -----

#1 slayerodd  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 79
  • Joined: 10-May 15

error LNK2001: unresolved external symbol

Posted 05 November 2015 - 07:20 AM

Hello :)/>

I'm making a game with C++ and SFML 2.3. This is my first "big" program so excuse me if I'm doing something wrong and please lead me in the right direction. Right now I'm setting up the classes and making the game menu. This is my output
    1>------ Build started: Project: Soda_Quest, Configuration: Debug Win32 ------
    1>  main.cpp
    1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderWindow GameWindow::mainWindow" ([email protected]@@[email protected]@@A)
    1>Menu.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderWindow GameWindow::mainWindow" ([email protected]@@[email protected]@@A)
    1>Gamewindow.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderWindow GameWindow::mainWindow" ([email protected]@@[email protected]@@A)
    1>main.obj : error LNK2001: unresolved external symbol "public: static class sf::Sprite Menu::bgSprite" ([email protected]@@[email protected]@@A)
    1>Menu.obj : error LNK2001: unresolved external symbol "public: static class sf::Sprite Menu::bgSprite" ([email protected]@@[email protected]@@A)
    1>Menu.obj : error LNK2001: unresolved external symbol "public: static class sf::Event Menu::MenuEvent" ([email protected]@@[email protected]@@A)
    1>Menu.obj : error LNK2001: unresolved external symbol "public: static class sf::Texture Menu::bgTexture" ([email protected]@@[email protected]@@A)
    1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function "int __cdecl invoke_main(void)" ([email protected]@YAHXZ)
    1>C:\Users\anton_000\Documents\Visual Studio 2015\Projects\Soda_Quest\Debug\Soda_Quest.exe : fatal error LNK1120: 5 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Gamewindow.h


    #ifndef WINDOW_H
    #define WINDOW_H
    
    #include <SFML/Graphics.hpp>
    
    class GameWindow {
    public:
    	static sf::RenderWindow mainWindow;
    
    	static void SetScreenWidth(int x);
    	static int GetScreenWidth();
    	static void SetScreenHeight(int x);
    	static int GetScreenHeight();
    
    	static void Initialize();
    
    private:
    	static int ScreenWidth;
    	static int ScreenHeight;
    };
    
    #endif




Gamewindow.cpp
    #include "Gamewindow.h"
    
    int GameWindow::ScreenWidth = 1024;
    int GameWindow::ScreenHeight = 576;
    
    void GameWindow::SetScreenWidth(int x) {
    	ScreenWidth = x;
    }
    
    int GameWindow::GetScreenWidth() {
    	return ScreenWidth;
    }
    
    void GameWindow::SetScreenHeight(int x) {
    	ScreenHeight = x;
    }
    
    int GameWindow::GetScreenHeight() {
    	return ScreenHeight;
    }
    
    
    void GameWindow::Initialize() {
    
    	GameWindow::mainwindow.create(sf::VideoMode
    		(GameWindow::GetScreenWidth(), GameWindow::GetScreenHeight()),
    		"Soda Quest");
    }




Menu.h


    #ifndef MENU_H
    #define MENU_H
    
    #include <SFML/Graphics.hpp>
    #include <iostream>
    #include "Gamewindow.h"
    
    
    class Menu {
    public:
    	static sf::Event MenuEvent;
    	static sf::Texture bgTexture;
    	static sf::Sprite bgSprite;
    
    	static void IncreaseOption(int x);
    	static void DecreaseOption(int x);
    	static void SetOption(int x);
    	static int GetOption();
    
    	static void Start();
    
    private:
    	static int Option;
    
    	
    };
    
    #endif





Menu.cpp
    #include "Menu.h"
    
    int Menu::Option = 0;
    
    void Menu::IncreaseOption(int x) {
    	Option += x;
    }
    
    void Menu::DecreaseOption(int x) {
    	Option -= x;
    }
    
    void Menu::SetOption(int x) {
    	Option = x;
    }
    
    int Menu::GetOption() {
    	return Option;
    }
    
    void Menu::Start() {
    
    	GameWindow::Initialize();
    
    	if (!bgTexture.loadFromFile("Recources/Background.png")) {
    		std::cout << "Error: Could not load Background.png" << std::endl;
    	}
    
    	bgSprite.setTexture(bgTexture);
    
    	while (GameWindow::mainwindow.pollEvent(MenuEvent)) {
    		if (Menu::GetOption() > 1) {
    			Menu::SetOption(0);
    		}
    		else if (Menu::GetOption() < 0) {
    			Menu::SetOption(1);
    		}
    
    		switch (MenuEvent.type) {
    		case sf::Event::Closed:
    			GameWindow::mainwindow.close();
    			break;
    		case sf::Event::KeyPressed:
    			switch (MenuEvent.key.code) {
    			case sf::Keyboard::Down:
    				Menu::IncreaseOption(1);
    				break;
    			case sf::Keyboard::Up:
    				Menu::DecreaseOption(1);
    				break;
    			}
    		}
    	}
    }





main.cpp
    #include <SFML/Graphics.hpp>
    #include "Game.h"
    #include "Menu.h"
    #include "Gamewindow.h"
    
    int main() {
    
    	while (GameWindow::mainwindow.isOpen()) {
    		Menu::Start();
    
    		GameWindow::mainwindow.display();
    		GameWindow::mainwindow.draw(Menu::bgSprite);
    	}
    }



Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2001: unresolved external symbol

#2 jimblumberg  Icon User is online

  • member icon

Reputation: 5443
  • View blog
  • Posts: 16,968
  • Joined: 25-December 09

Re: error LNK2001: unresolved external symbol

Posted 05 November 2015 - 07:22 AM

Please stop opening new topics for existing problems. I already answered this question here!

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1