SFML community forums

Help => General => Topic started by: rush905 on September 11, 2012, 12:42:54 am

Title: Linker Errors
Post by: rush905 on September 11, 2012, 12:42:54 am
Hi, I'm setting up SFML again for my project, but I keep getting these linking errors:

Error   10      error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::setFramerateLimit(unsigned int)" (__imp_?setFramerateLimit@Window@sf@@QAEXI@Z) referenced in function "void __cdecl invent(void)" (?invent@@YAXXZ) C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   12      error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ) referenced in function _main     C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   8       error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::close(void)" (__imp_?close@Window@sf@@QAEXXZ) referenced in function "void __cdecl invent(void)" (?invent@@YAXXZ)  C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   7       error LNK2019: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl sf::Keyboard::isKeyPressed(enum sf::Keyboard::Key)" (__imp_?isKeyPressed@Keyboard@sf@@SA_NW4Key@12@@Z) referenced in function "void __cdecl invent(void)" (?invent@@YAXXZ) C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   9       error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function "void __cdecl invent(void)" (?invent@@YAXXZ) C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   13      error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QBE_NXZ) referenced in function _main        C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   11      error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function "void __cdecl invent(void)" (?invent@@YAXXZ)    C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Game\main.obj
Error   14      error LNK1120: 7 unresolved externals   C:\Users\Anonymous\Documents\Visual Studio 2010\Projects\Game\Debug\Game.exe    1
 


I followed the tutorial for Visual C++, and I still can't figure it out. Any ideas?

Source:

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <Windows.h>
#include "Collision.hpp"
#include "Inventory.hpp"

const int sleepTime = 200;

       
int main()
{
        //Create window, and limit frame rate
        sf::RenderWindow window (sf::VideoMode(800, 600, 32), "Game", sf::Style::Default);
        window.setFramerateLimit(60);

//------------------------TEXTURES------------------------------

        //Declare textures
        sf::Texture texture;
        sf::Texture texture1;
        sf::Texture texture2;
        //Load image
        if(!texture.loadFromFile("Sprites/main.png"))
        {
                return 1;
        }
        if(!texture1.loadFromFile("Sprites/background.png"))
        {
                return 1;
        }
        if(!texture2.loadFromFile("Sprites/house.png"))
        {
                return 1;
        }

//------------------------SPRITES--------------------------

        //Creates and places the sprites
        sf::Sprite sprite;
        sf::Sprite background;
        sf::Sprite house;
        sprite.setPosition(400, 300);
        background.setPosition(0, 0);
        house.setPosition(440, 300);

        //Loads texture into sprite
        sprite.setTexture(texture);
        background.setTexture(texture1);
        house.setTexture(texture2);

//-------------------------RECTANGLES--------------------------------

        //Declares the rectangles
        sf::IntRect front(1, 1, 18, 24);
        sf::IntRect back (20, 1, 18, 24);
        sf::IntRect left (20, 26, 18, 24);
        sf::IntRect right (1, 26, 18, 24);
        //Steps
        sf::IntRect frontLeft(39, 1, 18, 24);
        sf::IntRect frontRight(39, 26, 18, 24);
        sf::IntRect backLeft();
        sf::IntRect backRight();
        sf::IntRect leftLeft();
        sf::IntRect leftRight();
        sf::IntRect rightLeft();
        sf::IntRect rightRight();

        sf::IntRect backgroundRect (0, 0, 800, 600);

        sf::IntRect houseRect (0, 0, 17, 22);

       
        //Crop sprites using rectangles defined above
        sprite.setTextureRect(front);
        background.setTextureRect(backgroundRect);
        house.setTextureRect(houseRect);

//-----------------------SOUND------------------------------------------------------

        //Declare the Sound Buffer
        sf::SoundBuffer footstepsBuffer;
        sf::SoundBuffer bumpBuffer;
        //Loads the sound file
        if(!footstepsBuffer.loadFromFile("Sounds/footsteps.wav"))
        {
                return 1;
        }
        if(!bumpBuffer.loadFromFile("Sounds/bump.wav"))
        {
                return 1;
        }

        //Declare sound
        sf::Sound footsteps;
        sf::Sound bump;
        //Load Buffer into Sound
        footsteps.setBuffer(footstepsBuffer);
        bump.setBuffer(bumpBuffer);

//-------------------------------MAIN-----------------------------

        //Main window loop
        while(window.isOpen())
        {
                sf::Event event;

                //Vectors used for collision
                sf::Vector2i spritePosition(sprite.getPosition());
                sf::Vector2i backgroundPosition(background.getPosition());
                sf::Vector2i housePosition(house.getPosition());

                //Sprite Vectors
                sf::Vector2i backVector(back.width, back.height);
                sf::Vector2i frontVector(front.width, front.height);
                sf::Vector2i rightVector(right.width, right.height);
                sf::Vector2i leftVector(left.width, left.height);

                //House Vectors
                sf::Vector2i houseVector(houseRect.width, houseRect.height);

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

                        if(event.key.code == sf::Keyboard::Insert)
                        {
                                sf::Image screenshot = window.capture();
                                screenshot.saveToFile("Screenshot.png");
                        }
                }

//------------------------------Inventory------------------------------------
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::I))
                {
                        sf::Thread window2(&invent);
                        inventoryIsOpen = !inventoryIsOpen;
                        if(inventoryIsOpen){
                                invent();
                                window2.wait();
                        }
                        else{

                        }
                }

//-----------------------------------MOVEMENT----------------------------------------

                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        //Change to stepping sprite
                        Sleep(sleepTime);
                        sprite.setTextureRect(back);
                        sprite.move(0, -24);
                        //Redeclaring the collision textures
                        sf::Vector2i spritePosition(sprite.getPosition());
                        sf::Vector2i housePosition(house.getPosition());
                        if(collision(spritePosition, backVector, housePosition, houseVector) == true)
                        {
                                sprite.move(0, 24);
                                bump.play();
                        }
                        else
                        {
                                footsteps.play();
                        }
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        //Change to stepping sprite
                        Sleep(sleepTime);
                        sprite.setTextureRect(front);
                        sprite.move(0, 24);
                        //Redeclaring the collision textures
                        sf::Vector2i spritePosition(sprite.getPosition());
                        sf::Vector2i housePosition(house.getPosition());
                        if(collision(spritePosition, frontVector, housePosition, houseVector) == true)
                        {
                                sprite.move(0, -24);
                                bump.play();
                        }
                        else
                        {
                                footsteps.play();
                        }
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        //Change to stepping sprite
                        Sleep(sleepTime);
                        sprite.setTextureRect(right);
                        sprite.move(19, 0);
                        //Redeclaring the collision textures
                        sf::Vector2i spritePosition(sprite.getPosition());
                        sf::Vector2i housePosition(house.getPosition());
                        if(collision(spritePosition, leftVector, housePosition, houseVector) == true)
                        {
                                sprite.move(-19, 0);
                                bump.play();
                        }
                        else
                        {
                                footsteps.play();
                        }
                }

                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        //Change to stepping sprite
                        Sleep(sleepTime);
                        sprite.setTextureRect(left);
                        sprite.move(-19, 0);
                        //Redeclaring the collision textures
                        sf::Vector2i spritePosition(sprite.getPosition());
                        sf::Vector2i housePosition(house.getPosition());
                        if(collision(spritePosition, rightVector, housePosition, houseVector) == true)
                        {
                                sprite.move(19, 0);
                                bump.play();
                        }
                        else
                        {
                                footsteps.play();
                        }
                }

                //Draw sequence
                window.clear(); //(Red, Green, Blue, (optional) Alpha) Alpha is transperency

                //Draw....

                window.draw(background);

                window.draw(house);

                window.draw(sprite);

                window.display();
        }
        return 0;
}
Title: Re: Linker Errors
Post by: eXpl0it3r on September 11, 2012, 01:25:12 am
Do you try to link SFML statically with the dynamic libraries or the other way around.

As for next time, please keep your code as minimal as possible, while still being complete and reproduces the error. E.g. a main function with the creation of a window would've here been enough to get a linker error...
Title: Re: Linker Errors
Post by: rush905 on September 11, 2012, 02:21:58 am
Yea, sorry about the length of the code. I was in a rush, and didn't have time to rewrite a basic program.

Anyways, I tried what you suggested, yet no luck.
Title: Re: Linker Errors
Post by: Laurent on September 11, 2012, 08:06:49 am
You must link to sfml-window(-d).lib, as explained in the tutorial.

And there's no need to post code for this kind of linker error , it's a project configuration issue ;)
Title: Re: Linker Errors
Post by: rush905 on September 11, 2012, 05:08:20 pm
Fixed. Thank you.