I followed a video on LinkedIn to setup SFML, but when I tried compiling the code get several errors, some of which are:
C2065 'Fullscreen': undeclared identifier
C3861 'RenderWindow':identifier not found
C2871 'sf': a namespace with this name does not exist
C2653 'Style':is not a class or namespace name
C2065 'VideoMode':undeclared identifier
C3861 'vm' :identifier not found
C2065 'vm' :undeclared identifier
C26444 Don't try to declare a local variable with no name(es.84)
C2146 syntax error:missing ';' before identifier 'vm'
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.
Related
This
//CSocket.h
#ifndef __SERVER_CSOCKET_H__
#define __SERVER_CSOCKET_H__
#include "winsock2.h"
#include "ws2tcpip.h"
#include <thread>
#include <stdio.h>
#include <string>
(cpp includes only the header)
//CSocket.cpp
#include "CSocket.h"
produces the following error messages in c:\program files (x86)\microsoft visual studio 12.0\vc\include\ratio
ratio(122): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(133): See reference to the instance of the just compiled class-template "std::ratio<_Nx,_Dx>".
ratio(124): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(44): error C2065: 'INTMAX_MAX': undeclared identifier
ratio(217): See reference to the instance of the just compiled class-template "std::_Safe_mult<0x01,0x01>".
ratio(36): error C2338: integer arithmetic overflow
ratio(44): See reference to the instance of the just compiled class-template "std::_Safe_multX<0x01,0x01,false>".
ratio(44): error C2039: 'value': Is not an element of 'std::_Safe_multX<0x01,0x01,false>'
ratio(44): error C2065: 'value': undeclared identifier
ratio(44): error C2057: Expected constant expression
ratio(44): error C2039: 'value': Is not an element of 'std::_Safe_multX<0x01,0x0989680,false>'
ratio(219): error C2975: "_Nx": invalid template argument for "std::ratio", expected compile-time constant expression.
ratio(116): See declaration of '_Nx'
ratio(219): error C2975: "_Dx": invalid template argument for "std::ratio", expected compile-time constant expression.
ratio(117): See declaration of '_Dx'
CSocket.cpp
Including std::thread in the .cpp and not in the header solves all errors but I don't know why it doesn't work in the header.
//CSocket.cpp
#include "CSocket.h"
#include <thread>
The only library I am using is jemalloc.
Might the error come from including jemalloc.h before mutex not from thread itself?
I had to #include <mutex> before #include "jemalloc.h" and not afterwards.
Works fine now, strange errors though.
I am having the same error, but the order of the includes is not useful for me. I think this has something to do with other includes that also use chrono and thread, so you can checkout that.
Are you using Visual Studio? Seems like more people is getting the same error: https://connect.microsoft.com/VisualStudio/feedback/details/800726/compiler-error
I have the same errors with VS2013 update 3. The problem seems to be the fact that INTMAX_MAX is not defined, but it is used in ratio.h.
My solution is to add
#define INTMAX_MAX INT64_MAX
before #include <ratio> in your file (if you do not have the line, you may add it).
The line to be included can be found in stdint.h - in your case, the right side can be different.
PS Another solution is to #include <stdint.h> and to define __STDC_LIMIT_MACROS. In this case, you may get some warnings about duplicate macros.
it occurs to the project when i use the CxImage as third party library and with threadpool in C++11. Separately they are all okay, while merged in the same project, that errors occur.
the solution is add the precompile option of _STDC_LIMIT_MACROS to
Property Pages -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions of the Project.
PS: my environment is : MFC/VS2015 && windows7 64bit
may it be helpful to somebody :)
When I create new c++ console application (with MFC checkbox checked) in VS2010 I have a lot of errors during compilation connected with prsht.h, zmouse.h, commctrl.h.
I did not change anything in this file so I have not idea what is wrong. What are this files and how I can compile program without errors?
Few of the many errors (113)
Error 13 error C1903: unable to recover from previous error(s); stopping compilation c:\program files (x86)\microsoft sdks\windows\v7.0a\include\prsht.h 97 1 qwert
Error 10 error C2065: 'CALLBACK' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\prsht.h 97 1 qwert
19 IntelliSense: expected a ';' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\commctrl.h 165 21
Error 2 error C2433: 'HWND' : 'inline' not permitted on data declarations c:\program files (x86)\microsoft sdks\windows\v7.0a\include\zmouse.h 141 1 qwert
You can try including the below in stdafx.h file before the #include "targetver.h" statement
#include "Winsock2.h"
#include "Windows.h"
#include "targetver.h"
These errors happened, because compiler treats symbols CALLBACK, HWND, etc. as new, it does not know them.
These symbols are defined in windows.h header file.
So the diagnosis is: windows.h was not included.
This can happen because of ruined SDK files, so you need to reinstall your SDK.
On my computer the header files are included in the following chain:
stdafx.h - afxwin.h - afx.h - afxver_.h - afxv_w32.h - windows.h, zmouse.h, commctrl.h
You can not include windows.h explicitly (as it was suggested before), because afxv_w32.h file has the following lines at the beginning:
#ifdef _WINDOWS_
#error WINDOWS.H already included. MFC apps must not #include <windows.h>
#endif
You can take a look at this: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/fff0ebaa-5153-40b9-89cf-cb9661abb2a4/
You may not cancelled the define code generated by VS:
(in framework.h)
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN
This define command told complier not include some specific headers like Windows. You may forgot to check the MFC support when creating the project.
After comment the #define, it may help.
I have a function:
SHFileOperationFunc(string item1, string item2, int operation, CuTest *tc)
It is used to do operations (move, delete or copy) directories. It works fine. But i am now trying to use stuff from dirent.h. When I include the file it causes huge problems with stuff from ShellAPI.h I use in SHFileOperationFunc. I got dirent.h as per http://www.softagalleria.net/dirent.php.
After I include the file I get errors like:
error C2065: 'FO_DELETE' : undeclared identifier
error C2065: 'FO_COPY' : undeclared identifier
error C2065: 'FO_DELETE' : undeclared identifier
error C2065: 'FO_DELETE' : undeclared identifier
These are defined in ShellAPI.h. When I hover over them in VS it says the value they have so it is seeing them. Anyone know why including this file is having this effect?
Using dirent.h on a Windows machine is unadvisable, it is a Unix header. The file you downloaded screws up the rest of your #includes. Either put if after #include <windows.h> or edit the file and delete the #define for WIN32_LEAN_AND_MEAN. Putting that in a header is, well, mean. It causes a large number of declarations to be skipped in the Windows headers.
I am compiling a Matlab mex file (Using VS2010 under Windows), and the following 2 includes:
#include <algorithm> // for std::copy
#include "mex.h"
give me compile error:
1>d:\svn\trunk\dev\matlab\extern\include\matrix.h(337): error C2371:
'char16_t' : redefinition; different basic types
I have tried putting it in a namespace:
namespace Algo {
#include <algorithm>
}
But then I get tons of other compile errors, without even using anything defined in <algorithm>, for example:
Error 1 error C2039: 'set_terminate' : is not a member of '`global namespace'' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\exception 192
Error 2 error C2873: 'set_terminate' : symbol cannot be used in a using-declaration C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\exception 192
How can I solve this?
Putting an standard header in a namespace doesn't sound like a good idea, even though you are not using any of the methods or classes there, there is a pretty big chance that another header might (like the mex.h). Putting the namespace around the mex header seems much less probable to create a conflict.
Also including one header before the other might also prevent such a conflict. Some headers take into account that some symbol might already be defined before redefining them (library developer really should take care to do this)
In some cases reading the headers might also give you a good clue what is going on. Some times it might be as simple as defining a symbol, which tells the header to skip the redefinition.
I'm writing a DLL plugin for a windows application,
after adding the following includes:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
I get a wonderful compilation error:
Error 3 error C2143: syntax error : missing ';' before '__cdecl' c:\program files (x86)\microsoft visual studio 9.0\vc\include\locale.h 111 LeverateMetaTraderServerAPI
Help?
I'm no authority on C++, but this sort of thing happens when you miss a ; off the end of your class definition.
someone who isn't really smart added this :
#define __declspec(dllexport) __stdcall APIENTRY
to one of the API .h files your including
This error is (with high probability) not caused by Boost. It's probably either the result of a missing semicolon somewhere else in your code or triggered by a missing header include leaving some macro undefined.