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 :)
Related
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.
In my code I use DBL_MAX, which is defined in math.h. In VS2010 it works fine, but in VS2008 I get an error:
error: C2065: 'DBL_MAX' : undeclared identifier
Is DBL_MAX available in VS2008?
Turns out I was being dumb, I should have checked the actual header - it's in float.h, not math.h. It seems that math.h includes float.h in VS2010 but not in VS2008.
What confused me was that it was working in VS2010, so I just assumed DBL_MAX it's not available for VS2008.
So adding it fixed the issue:
#include <math.h>
#include <float.h>
I'm posting this in case anyone else ever makes the same mistake.
I'm compiling in VS 2010 with boost 1_53.
I'm also using boost's threads.
during compilation i'm getting bunch of errors like this
c:\program files (x86)\microsoft visual studio 10.0\vc\include\ctime(18): error C2039: 'clock_t' : is not a member of '`global namespace''
all errors are about ctime and c_time.hpp.
i've searched around for the solution but without success.
can anyone, please, help?
here some part of code.
#define BOOST_THREAD_USE_DLL
#include <boost/optional.hpp>
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
Something, somewhere in your codebase is including a different "time.h". I just discovered this migrating code from Linux to Windows - Because windows is case insensitive, a local "Time.h" (note the capital) was included as "time.h", causing the error that you see.
According to someone's post, FFMPEG can cause this problem via this precise mechanism.
Please look through your codebase and/or libraries for a "time.h" to see if this is happening. Otherwise, an alternate option is to output the fully pre-processed source to see what is actually being compiled in the offending file.
i've this simple code but i dont where is the error of this all
#include <iostream.h>
#include <fstream.h>
#include <string.h>
using namespace std;
int main(){
string s;
cout<<"Entrer nom de fichier avec le source";
cin s;
ifstream fout;
fout.open(s);
s=fout.getche();
fout.close();
cout<<s;
return 0;
}
cause the errors showing after compiling are:
d:\workespace3.cpp(5) : error C2871: 'std' : does not exist or is not a namespace
d:\workespace3.cpp(8) : error C2653: 'std' : is not a class or namespace name
d:\workespace3.cpp(8) : error C2065: 'string' : undeclared identifier
d:\workespace3.cpp(8) : error C2146: syntax error : missing ';' before identifier 's'
d:\workespace3.cpp(8) : error C2065: 's' : undeclared identifier
d:\workespace3.cpp(10) : error C2146: syntax error : missing ';' before identifier 's'
d:\workespace3.cpp(13) : error C2039: 'getche' : is not a member of 'ifstream'
c:\program files (x86)\microsoft visual studio\vc98\include\fstream.h(98) : see declaration of 'ifstream'
Error executing cl.exe.
workespace3.obj - 7 error(s), 0 warning(s)
Don't use the .h forms of the include files, those are meant for backwards compatibility with C. Use for example #include <string>.
You have many errors:
1- You are using deprecated header files. Standard C++ library headers come in headers without ".h". So that would be:
#include <iostream>
#include <fstream>
#include <string>
2- getche() is not a proper method of ifstream. Here is the complete list of methods of ifstream:
http://www.cplusplus.com/reference/fstream/ifstream/
You probably meant to use get() or getline()
3- You are missing ">>" between "cin" and "s".
4- You are using a very old IDE. There are multiple newer and free IDEs out there. Notably you can have VC++ 2012 Express for free. It will be more standards compliant and also include better tools and support for C++11
If the compiler supports the C++98 standard headers, then use them
#include <iostream> // no .h
If it only supports the ancient pre-ISO headers that you're including, then just leave out any mention of namespace std. In those dark days, the standard library was just dumped into the global namespace.
I would consider using a compiler from this millennium; you'll find it easier to get help from people whose memory of the 1990s is less than perfect.
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.