1
votes

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
1
Your bug is your don't have #include "pch.h" as the first line. In Visual Studio when using precompiled headers the compiler ignores every line above #include "pch.h"drescherjm
Although, in this particular case, your 'bug' is apparent, you really should post your code as a (code-formatted) text block, rather than as an image. Otherwise, your question is likely to be closed as "Needs details or clarity!" I would recommend you edit your question to do that.Adrian Mole

1 Answers

1
votes

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.