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

Author Topic: Error link 1120:1 unresolved externals [Snake Game(sorry)]  (Read 1609 times)

0 Members and 1 Guest are viewing this topic.

Serilda

  • Guest
Error link 1120:1 unresolved externals [Snake Game(sorry)]
« on: March 20, 2016, 03:57:44 pm »
Sorry for my many snake game questions guys,




#include "stdafx.h"
#include <SFML\Graphics.hpp>



#include <iostream>
#include <time.h>

#include <stdlib.h>
#include<vector>
#include <algorithm>

bool intersects(const sf::RectangleShape & r1, const sf::RectangleShape & r2){
        sf::FloatRect snake = r1.getGlobalBounds();
        sf::FloatRect spawnedFruit = r2.getGlobalBounds();
        return snake.intersects(spawnedFruit);

}

sf::RectangleShape generateFruit() {


        sf::RectangleShape fruit;
        fruit.setFillColor(sf::Color::Yellow);
        int fruitx = rand() % 400;
        int fruity = rand() % 400;
        fruit.setPosition(fruitx, fruity);
        fruit.setSize(sf::Vector2f(5, 5));

        return fruit;


}
int main()
{
        srand(time(NULL));
        int width = 400;
        int height = 400;
        sf::VideoMode videomode(width, height);
        sf::RenderWindow window(videomode, "Snake");
        sf::RectangleShape snake;

        snake.setFillColor(sf::Color::Red);
        snake.setSize(sf::Vector2f(20, 20));
        snake.setPosition(100, 100);
        sf::Clock clock;
        sf::Time t1 = sf::seconds(20);
        sf::RectangleShape spawnedFruit;
        while (window.isOpen()) {
                window.clear();
                window.draw(snake);



                sf::Time elapsed1 = clock.getElapsedTime();
                if (elapsed1 >= t1) {


                        spawnedFruit = generateFruit();

                        clock.restart();

                }

                window.draw(spawnedFruit);

                window.display();
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if ((event.type == sf::Event::Closed) ||
                                ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
                                window.close();
                }


                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))

                        snake.move(0, -0.1);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        snake.move(0, 0.1);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        snake.move(-0.1, 0);
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        snake.move(0.1, 0);
                if (intersects(snake, spawnedFruit))
                        std::cout << "Intersects";





        }

}
 

This gives me the Errors:

Error 7 error LNK2001: unresolved external symbol "public: bool __thiscall sf::Rect::intersects(class sf::Rect const &)const " (?intersects@?$Rect@M@sf@@QBE_NABV12@@Z)

Error 8 error LNK1120: 1 unresolved externals

The errors appear only when I add the bool intersects function.

Any idea why is that or how to fix it? Thank you.

ka0s420

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • Email
Re: Error link 1120:1 unresolved externals [Snake Game(sorry)]
« Reply #1 on: March 21, 2016, 04:13:28 am »
strange, it complies from my visual studio. All I can say is that its a link error, which means that one of the .lib files is set up wrong, missing or the libs directory is wrong, although why it only does it when you add the bool intersecs function is beyond me. :/

Is it possible that you only set up libs for debug and you're running it in release, or vice versa? Best bet would be to try re-linking everything and making sure you're using the right configuration etc.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Error link 1120:1 unresolved externals [Snake Game(sorry)]
« Reply #2 on: March 21, 2016, 12:49:10 pm »
It can also occur when linking to a (even slightly) different version of the library from the actual DLLs that are in use. If you have installed more than one version, consider ensuring that that everything is from the same version.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything