c++ boost compilation catastrophe - c++

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.

Related

Compile errors when including std::mutex before jemalloc.h

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 :)

C++ syntax error and missing type specifier

Visual C++ 2008 gives me this weird error, so I stripped out all of the excess stuff in my header file (util.h
), and it boils down to this:
#ifndef UTIL_H
#define UTIL_H
void pause();
#endif
When I try to compile the above code I get this:
Compiling...
util.cpp
util.h(4) : error C2144: syntax error : 'void' should be preceded by ';'
util.h(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<snip>
I am deeply confused. Even if I comment out the ifndef, define, and endif, preprocessor directives, It still says the same thing.
After hours of looking, I finally figured it out!
The error is not in the header file itself. Header files are copied and pasted into source files, where they are included. So I looked where I included the file, and I saw in util.cpp:
#include "stdafx.h"b
#include "util.h"
<snip>
That extra 'b' is causing the error. C++ thinks it is a variable, but doesn't see a type specifier, so it assumes 'b' is a new integer. Then it thinks I should terminate its declaration with a ';' to precede 'void'. The entire issue is just a stupid extra character, and a not very helpful error message.

Qt QPainterpath.h errors

I am currently working on a Qt application with many #include files from the Qt library. The project is quite large and I have encountered a strange problem when building. The errors displayed are all inside the QPainterpath.h file, but has nothing to do with calls to it from my project. The errors all look like this:
c:\qt\4.8.4\include\qtgui../../src/gui/painting/qpainterpath.h(397) : error C2143: syntax error : missing ';' before '::'
c:\qt\4.8.4\include\qtgui../../src/gui/painting/qpainterpath.h(397) : error C2059: syntax error : '::'
c:\qt\4.8.4\include\qtgui../../src/gui/painting/qpainterpath.h(398) : error C2143: syntax error : missing ';' before '{'
c:\qt\4.8.4\include\qtgui../../src/gui/painting/qpainterpath.h(398) : error C2447: '{' : missing function header (old-style formal list?)
c:\qt\4.8.4\include\qtgui../../src/gui/painting/qpainterpath.h(405) : warning C4003: not enough actual parameters for macro 'elementCount'
I encountered this once before and was able to solve it by moving some Qt #include statements called before other class headers below them. I can't seem to figure out what in particular is causing it this time though. Any thoughts would be great!
Thanks!
I've seen this happen when you forget to close a class definition with a semicolon. If you look at the output from the compiler, and see which file was compiled right before this error started, you may have your answer. Look for syntax errors with missing a ; or an extra } or a missing } at the end of the previously compiled file.
It could also be from a .h file listed above your #include <QPainter> call that has the errors.
Hope that helps.
I'm working with RyGuyFalcore and figured out why this is happening in our code, and nobody else is seeing it. The issue is that our legacy code was redefining the elementCount macro. Therefore, if we included that portion of our legacy code before we included the Qt code, the wrong macro was getting used :( Figured I would post this here to avoid any wild goose chase that others may run into if they hit a similar bug.

Error after created new c++ console application

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.

type redefinition error when including 2 header files

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.