0
votes

I have been trying to install SFML for months with no luck. Today I decided to try again. At first it didn't even find the SFML\graphics.hpp include file, but I finally fixed that. Now I am getting a new error. When compiling the code below, I get a bunch of errors. Here is the code:

#include <SFML\Graphics.hpp>

int main() {
    int window_width = 640;
    int window_height = 480;

    sf::RenderWindow window(sf::VideoMode(window_width, window_height), "SFML Tutorial");

    while (window.isOpen()) {
        // handle events

        // update game logic

        window.clear();

        // draw objects

        window.display();
    }

    return 0;
}

And here are the errors: Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main SFML Template C:\Users\theyo\Desktop\SFML\SFML Template\SFML Template\SFML Template.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function _main SFML Template C:\Users\theyo\Desktop\SFML\SFML Template\SFML Template\SFML Template.obj 1

I actually get too many to put into this post, and I don't know where I'd find a log file to give you. I know probably no one will be able to help, but please if you understand then try to help.

I also get 6 of these warnings: Severity Code Description Project File Line Suppression State Warning LNK4272 library machine type 'x64' conflicts with target machine type 'x86' SFML Template C:\Users\theyo\Desktop\SFML\External Libraries\SFML\lib\sfml-graphics-d.lib 1

  • one for each library file in SFML.

Today alone, I have frame for frame copied the following video https://www.youtube.com/watch?v=_9yem5dJt2E with no luck. I am getting desperate. Thanks.

1
I forgot to mention - I am using Visual Studio 2019 and all my configurations are linked up correct, as per the video provided. - Kane Keylewer
library machine type 'x64' conflicts with target machine type 'x86' SFML Means you are mixing 32 and 64 bit. - drescherjm
That's only a warning - so it's not essential to the build. The build errors are what I'm worried about. I know what x64 and x86 conflict is, I just don't understand where they're coming from as I copied the video second for second and he didn't get the error. Thank you though :) - Kane Keylewer
You should spent some time reseaching the separate compilation model used by C++. What libraries are, what header files are, what compilation is, what linking is etc. etc. Tools like Visual Studio make it seem easy because you just push a button and everything builds. But when things go wrong you do need to understand what's going on behind the scenes. - john
You likely should have a choice between Win32 and x64 on your toolbar right next to Debug in Visual Studio. However to use the choice you have to add the proper libraries to the other configuration. SFML has different libraries for debug mode than they do for release mode and you should not select the wrong ones because this is Undefined Behavior. The debug libraries should have a d in the name close to the .lib the release will not have this d. - drescherjm

1 Answers

0
votes

There seems to be a problem with your linkers. Makes sure you have linked the correct files for the correct architecture/platform and their dependencies as well (in the correct order, of course). That being said, it could be that your downloaded version of SFML does not match the compiler you are using it on. You could always recheck that or build SFML yourself from source. If you don't want to go through all that then I have a template on GitHub for SFML with VS2019.

SFMLVS2019Template

Just go through the readme if you can't figure out something. Also, as someone mentioned, I think you should look a bit more into how compilers and linkers work. IDEs definitely make it seem easier than it is.