John Emechete
John Emechete

Reputation: 11

How can I fix SFML errors in VS 2019 on windows?

I followed a video on LinkedIn to setup SFML, but when I tried compiling the code get several errors, some of which are:

  1. C2065 'Fullscreen': undeclared identifier
  2. C3861 'RenderWindow':identifier not found
  3. C2871 'sf': a namespace with this name does not exist
  4. C2653 'Style':is not a class or namespace name
  5. C2065 'VideoMode':undeclared identifier
  6. C3861 'vm' :identifier not found
  7. C2065 'vm' :undeclared identifier
  8. C26444 Don't try to declare a local variable with no name(es.84)
  9. C2146 syntax error:missing ';' before identifier 'vm' screenshot of the code and the compiler errors

Upvotes: 1

Views: 232

Answers (1)

Adrian Mole
Adrian Mole

Reputation: 51845

Assuming (from its name) that "pch.h" generates and/or uses the precompiled header for your build, then that has to be the very first header included in any source file. Otherwise, anything 'gleaned' from headers included before it will be lost, as the compiler only looks in that precompiled header and files included afterwards.

So, just rearrange your top three lines as follows:

#include "pch.h" // MUST be the first header included!
#include <iostream>
#include <SFML/Graphics.hpp>

For an interesting (and informative) discussion about precompiled headers in Visual Studio, see this Stack Overflow question, and the answers there: Precompiled Headers.

Upvotes: 1

Related Questions