c++ - Can't get passed error LNK2001: unresolved external symbol, even if I seem to have included what is needed -
i trying create game c++ , smfl 2.0 , cant pass error , it's driving me crazy. have been reading around internet , seems can caused because of forgotten includes, still cant see have gone wrong. have included smfl 2.0 library in project properties section under c++ -> general -> additional include directories , under linker -> general -> additional library directories.
i'm blank , error message get:
1>------ build started: project: pang, configuration: debug win32 ------ 1> game.cpp 1> generating code... 1> skipping... (no relevant changes detected) 1> pang.cpp 1>game.obj : warning lnk4075: ignoring '/editandcontinue' due '/incremental:no' specification 1>game.obj : error lnk2001: unresolved external symbol "private: static class playerpaddle game::_player1" (?_player1@game@@0vplayerpaddle@@a) 1>c:\users\alexander\desktop\c++\projects\pang\debug\pang.exe : fatal error lnk1120: 1 unresolved externals ========== build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
microsoft visual c++ doesnt show syntax grammar errors red underline when im looking around code looks syntax ok. here relevant lines of code:
i have of general includes here:
stdafx.h
#pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> #include <windows.h> #include <sfml/system.hpp> #include <sfml/graphics.hpp> #include <sfml/window.hpp> #include <sfml/audio.hpp> #include <map> #include <iostream> #include <cassert> #include <list>
visiblegameobject.h
#pragma once class visiblegameobject { public: visiblegameobject(); virtual ~visiblegameobject(); virtual void load(std::string filename); virtual void draw(sf::renderwindow &window); virtual void setposition(float x, float y); private: sf::sprite _sprite; sf::texture _image; std::string _filename; bool _isloaded; };
visiblegameobject.cpp
#include "stdafx.h" #include "visiblegameobject.h" visiblegameobject::visiblegameobject() { _isloaded = false; } visiblegameobject::~visiblegameobject() { } void visiblegameobject::load(std::string filename) { if (_image.loadfromfile(filename) == false) { _filename = ""; _isloaded = false; } else { _filename = filename; _sprite.settexture(_image); } } void visiblegameobject::draw(sf::renderwindow &renderwindow) { if (_isloaded) { renderwindow.draw(_sprite); } } void visiblegameobject::setposition(float x, float y) { if (_isloaded) { _sprite.setposition(x,y); } }
this class helps me use smfl library draw images on rendered window.
playerpaddle.h
#pragma once #include "visiblegameobject.h" class playerpaddle : public visiblegameobject { public: playerpaddle(); ~playerpaddle(); };
playerpaddle.cpp
#include "stdafx.h" #include "visiblegameobject.h" #include "playerpaddle.h" playerpaddle::playerpaddle() { } playerpaddle::~playerpaddle() { }
game.h
#pragma once #include "playerpaddle.h" class game { public: static void start(); private: static bool isexiting(); static void gameloop(); static void showsplashscreen(); static void showmenu(); enum gamestate { uninitialized, showingsplash, paused, showingmenu, playing, exiting }; static gamestate _gamestate; static sf::renderwindow _mainwindow; static playerpaddle _player1; };
game.cpp
#include "stdafx.h" #include "game.h" #include "splashscreen.h" #include "mainmenu.h" void game::start(void) { if(_gamestate != uninitialized) { return; } _mainwindow.create(sf::videomode(1024,768,32),"pang!"); //_player1.load("images/paddle.png"); //_player1.setposition((1024/2)-45, 700); _gamestate = game::showingsplash; while(!isexiting()) { gameloop(); } _mainwindow.close(); } bool game::isexiting() { if(_gamestate == game::exiting) { return true; } else { return false; } } void game::gameloop() { switch(_gamestate) { case game::showingmenu: { showmenu(); break; } case game::showingsplash: { showsplashscreen(); break; } case game::playing: { sf::event currentevent; while (_mainwindow.pollevent(currentevent)) { _mainwindow.clear(sf::color(0,0,0)); //_player1.draw(_mainwindow); _mainwindow.display(); if (currentevent.type == sf::event::closed) { _gamestate = game::exiting; } if (currentevent.type == sf::event::keypressed) { return; if(currentevent.key.code == sf::keyboard::escape) { showmenu(); } } } break; } } } void game::showsplashscreen() { splashscreen splashscreen; splashscreen.show(_mainwindow); _gamestate = game::showingmenu; } void game::showmenu() { mainmenu mainmenu; mainmenu::menuresult result = mainmenu.show(_mainwindow); switch(result) { case mainmenu::exit: { _gamestate = game::exiting; break; } case mainmenu::play: { _gamestate = game::playing; break; } } } game::gamestate game::_gamestate = uninitialized; sf::renderwindow game::_mainwindow;
this code compiles , runs when 3 lines of codes starting _player1 in game.cpp commented out. when not commented out lnk2001 error , cant passed , quite frustrating.
would nice if had input on wrong here.
best of regards, alexander
your game.cpp misses definition of game::_player1:
playerpaddle game::_player1;
Comments
Post a Comment