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

Author Topic: Unresolved external symbol  (Read 4150 times)

0 Members and 1 Guest are viewing this topic.

sjames

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Unresolved external symbol
« on: November 01, 2021, 04:29:36 pm »
I am getting the following error:
Quote
unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default
after some debugging I found out that the function window.draw() causes it. I think that it might be something wrong with my linking since it works just fine in release mode.

#include <SFML/Graphics.hpp>
#include "Graphics.h"

using namespace sf;
using namespace std;

sf::Texture grey;
sf::Texture green;

int main()
{
int size = 75;
        RenderWindow window(VideoMode(750, 750), "Chess");

        Event event;
        void CreateTextures();
        while (window.isOpen()) {

                while (window.pollEvent(event)) {

                        if (event.type == Event::Closed) {

                                window.close();
                        }
                }

                window.clear(Color::Black);

                std::vector<Sprite> sprites(64);
                for (int y = 0; y < 8; y++)
                {
                        for (int x = 0; x < 8; x++)
                        {
                                int index = y * 8 + x;
                                if (index % 2 == 0)
                                {
                                        sprites.at(index).setTexture(grey);
                                        sprites.at(index).setPosition(75 + x * size, 75 + y * size);
                                        window.draw(sprites.at(index)); // ERROR
                                }
                                else
                                {
                                        sprites.at(index).setTexture(green);
                                        sprites.at(index).setPosition(75 + x * size, 75 + y * size);
                                        window.draw(sprites.at(index)); // ERROR
                                }
                        }
                }
                window.display();
        }
        return 0;
}

void CreateTextures()
{
        Uint8* pixels = new Uint8[75 * 75 * 4];

        //Creating Grey Texture
        grey.create(75, 75);
        for (int i = 0; i < 75 / 2; i += 4)
        {
                pixels[i] = 188;
                pixels[i + 1] = 150;
                pixels[i + 2] = 86;
                pixels[i + 3] = 255;
        }
        grey.update(pixels);

        //Creating Green Texture
        green.create(60, 75);
        for (int i = 0; i < 75 / 2; i += 4)
        {
                pixels[i] = 188;
                pixels[i + 1] = 150;
                pixels[i + 2] = 86;
                pixels[i + 3] = 255;
        }
        green.update(pixels);
}
(No, the code is not working properly. I still have to debug it but I need to be able to compile it first)

edit: These are the .lib's that I link:
sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib
sfml-audio-d.lib
sfml-network-d.lib
« Last Edit: November 01, 2021, 04:34:46 pm by sjames »

Skaldi

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Unresolved external symbol
« Reply #1 on: November 01, 2021, 11:24:30 pm »
The error message is definetley a linker error.

A possible solution could be to compare which libraries you are linking in release and in debug configuration. Maybe the debug configuration is just missing one or more.

As soon as I am at my computer I can look it up what I which ones I link to as my debug config just works fine.

Skaldi

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Unresolved external symbol
« Reply #2 on: November 02, 2021, 11:15:41 am »
Hello,

in my debug configuration I have following libraries:
winmm.lib
opengl32.lib
freetype.lib
sfml-graphics-s-d.lib
sfml-window-s-d.lib
sfml-system-s-d.lib
sfml-audio-s-d.lib
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Unresolved external symbol
« Reply #3 on: November 02, 2021, 11:50:56 am »
In those ~4h between the first two posts, you could have also spent some time googling the error, which will have provided StackOverflow and SFML forum answers from the past ;)

If you want to link SFML statically, but have to define SFML_STATIC.
If you want to link SFML dynamically, you cannot define SFML_STATIC
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything