How to fix header file error? - c++

So, my question is how to fix some error in header file, to run program normally? For example I use c++ builder 2010 and when winuser.h file is included, the program always get error like this
Checking project dependencies...
Compiling Project7.cbproj (Debug
configuration) [BCC32 Error]
winuser.h(47): E2257 , expected Full
parser context
File6.cpp(4): #include c:\program files (x86)\embarcadero\rad
studio\7.0\include\winuser.h [BCC32
Error] winuser.h(48): E2257 , expected
Full parser context
i try to replace that file with original from default installation, but that still get same error, how to fix that?

The error is almost certainly caused by whatever code appears before line 4 of File6.cpp. Most likely that is another header file, in which case it is likely that the code therein is malformed - a missing semicolon or brace for example.
The quickest way to verify that winuser.h is not the issue is to change the order of inclusion so that winuser.h is included first.
Another possibility is that something in winuser.h is dependent on some other header not previously included or directly included in winuser.h. Most Win32 API headers are included by windows.h, and it is generally advisable to include windows,h rather than either of its children.

The message is hard to read but the actual error is "E2257 , expected" (coma expected)
From the RAD studio documentation:
A comma was expected in a list of declarations, initializations, or parameters.
This problem is often caused by a missing syntax element earlier in the file
or one of its included headers.
The error message give you the line where it happened and you should probably look before that. There is probably some '}', ')' or ';' or other syntaxic closer missing in your code just before the error (likely before inclusion of the header file in your code). Full error message (you truncated it) or actual code would make it easier to spot.
It is also possible, even if unlikely, that the error is in one of the headers included in winuser.h.

Related

Why is clang-tidy scanning other header files?

I'm running clang-tidy on a header file header.h. However as some of the warning outputs, it's outputting system headers:
.../include/c++/8/bits/std_abs.h:46:8: error: expected identifier or '(' [clang-diagnostic-error]
extern "C++"
../include/c++/8/cctype:62:1: error: unknown type name 'namespace' [clang-diagnostic-error]
namespace std
../include/c++/8/cctype:62:14: error: expected ';' after top level declarator [clang-diagnostic-error]
namespace std
..
etc
The problem: I don't want to see the warnings for anything other than the source file I'm scanning, for either a source file or header file.
I've tried implementing the fix here (What is the correct way of providing header-filter for clang-tidy in Cmake?) using --header-filter but it didnt work. I added the path to the header file that I was scanning in the regex, but I was still seeing the system header warnings.
For clang-tidy to work your code needs to be compile-able by the clang backend to generate an AST. This is apparently not the case since clang-diagnostic-error is basically a compilation error.
The problem is you are including headers that cannot be compiled by clang, there is no way to filter that out.

so many error when i add certain .cpp file

i made small program which does some functions and i tested it and it worked as i wish.
Then i add its .h and .cpp files to another program to use it but when i add the .cpp file it gives me 100s of errors related to boostmultiindex which i use in the added .cpp file.
i do not know what is happening.
the errors include the following"this is sample of errors":
Error C2516 'boost::mpl::if_<C,F1,F2>::type': is not a legal base class
Error C2039 'type': is not a member of 'boost::iterators::iterator_category_to_traversal<int>'
Error C3203 'type': unspecialized class template can't be used as a template argument for template parameter 'U', expected a real type
Error C2653 'safe_mode': is not a class or namespace name
Error C2143 syntax error: missing ',' before '<'
i did not attach code or files because i do not know where to start.
i can update the post based on any guidance.
update:
i think the problem is related to certain header file which i put in it most includes for all my cpp files.
this might lead to cyclic dependency problem which might led to ignoring some includes.
because when i exclude this large include file the errors are much decreased.
i will try to reorder the includes and see if they make difference.
update:
now i commented two lines in the large include file and it removed the errors related to this problem.
the two lines are:
//??#include "modules/utils/utils.h"
//??#include "modules/utils_dst/utils_dst.h"
i do not why these two lines makes these errors
is it related to the fact that the two files are in subdirectories???
Make sure of the following:
When including the .h and .cpp files that you have the full path not just the name of the file.
There are no variables, functions, etc. having the same name/signature in both the files your including and the project file you are including to. If there is, then use namespace to differentiate between conflicts.
You have added all dependencies of the files you want to include to the file you want to include into.

Problem with include guard

When I add an include guard to my header file for a Visual C++ project, it gives me the following warning and error:
warning C4603: '_MAPTEST_H' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
.\MapTest.cpp(6) : use of precompiled header** // the precompiled header stdafx.h is included in this line
.\MapTest.cpp(186) : fatal error C1020: unexpected #endif
but when I add the precompiled header before the include guard, no warning or error is emitted. What is the reason for this?
Two problems I can think of:
According to this, Visual C++ won't compile anything before the line where you include stdafx.h - so that line needs to be the very first one in the file. If you put it after the macro definition, it gets skipped, hence the errors you're seeing.
Identifiers starting with a leading underscore and a capital letter (or double leading underscores) are reserved, which might be causing a name conflict. see this answer for more details.
Try opening stdafx.cpp and add your macro definition there!
I hope your problem is solved

compilation error while #import tlb file in COM automation

I am trying to #include an application tlb file in VC++ project.
Getting following compilation errors, after #import "CANoe.tlb" in my project source file. -
unknown character '0x1'
syntax error : missing ';' before identifier 'A'
missing type specifier
int assumed. Note: C++ does not support default-int
'{' : missing function header (old-style formal list?)
Please suggest, if I am doing some wrong.
Also, is there a way to verify the .tlb file contents and resolve these errors. Is it possible to make corrections in tlb file ? If so, how do I create a updated tlb
Thanks in advance
My first thought is that you are dealing with a file that is not a TLB. Or at least, is corrupted.
I would try and bring up the TLB in OleView. This should give you a quick sanity check that the TLB is or is not valid.
If the type library file is intact the next step is to try find the generated .tlh and .tli files - they will be located in some temporary folder and have the same name as type library file and ".tlh"/".tli" extensions. If they exist examining them might help a lot.
import directive does two things - it builds the ".tlh" and ".tli" files and then includes them - the error messages correspond to the second stage - when the C++ compiler just refuses to compile them. Examining the files will likely help identify the reason.

Visual Studio 2008, error c2039: 'set_new_handler' : is not a member of 'std'

So the other day I went to compile a VC++ project I am working on and all of a sudden I get errors in almost all of my files saying:
new.h: error C2039: 'set_new_handler' : is not a member of 'std
new.h: error C2039: 'set_new_handelr' : symbol cannot be used in a using-declaration
"new.h" and 'set_new_handler' are not being used in any of my files, so I have no idea how or why these errors are suddenly appearing since they relate to a windows/VS library file.
Would anyone know what I can do to clear this error and compile my code again?
UPDATE After examining the files being included upon compilation, some files are including and some are . The problem is that is being included in afxwin.h and is being included in a third-party library. I honestly have no idea what to do with this problem...no other developers that have played with this code are running into this problem, may it be a settings problem? I am not using precompiled headers.
If I were to hazard a guess, I would say that <new.h> declares set_new_handler in the global namespace and <new> declares it within the std namespace. Some code is including <new.h> and expecting it to act as if it had included <new>. I would suspect either some 3rd party library/header or a precompiled header as suggested by Evan.
You can narrow down the culprit using either /showIncludes or pre-processing a source code file (using /E) and examining the output. I usually use the latter and look at the #line directives in the output file to figure out the include chain.
Good luck.