i get an error "missing ; before identifier".
no ; is missing.
this error appears only when i include one of the files:
MAPIDefS.h
Windows.h
wtypes.h
WinBase.h
what could be the problem?
Thanks a whole lot. I tried everything everybody suggested and it worked. The problem was I used a name in my file which was also defined in these header files.
All of these include files, except for MAPIDefs.h, are already included by Windows.h.
Manually including them will cause obscure errors.
You should remove all of the includes except for Windows.h and MAPIDefs.h.
Check the file which includes that header file, or any previous includes. Sometimes the error may propagate from previous files.
The most common mistake which gives such strange errors is omitting the semicolon ; after a class definition in one of the headers.
That's all I can say without seeing any code, hope that helps.
include windows.h before other windows api files.
If you have other include files or #define statements before the windows api files then you probably have define a symbol that is used in the API files. You should check that.
Related
I am trying to introduce precompiled headers into my project because of long compile times in my project right now. I have a main project that includes a main function and all the real code is in the DLL project(they are linked together.) I named my precompiled header "vpch.h" and i created a vpch.cpp that includes vpch.h. I am using visual studio 2017 so I went into the properties of vpch.cpp and selected Create. Then I added vpch.h as the first thing in all my cpp files. All files are set to use precompiled headers and reference vpch.h Every CPP files throws the error:
Error C1010 unexpected end of file while looking for precompiled header.
Did you forget to add '#include "vpch.h"' to your source?
I am at a loss as to what to do because I have followed many tutorials and can't find a reason for this. As well as most issues that pop up on google are people just accidentally including precompiled headers.
My only thought is that maybe in the section in properties where it asks for the name of the precompiled header, I need to do more than put "vpch.h" and maybe an exact file location? Any help with this is super appreciated.
EDIT
From further debugging it would appear that all but ONE cpp file is throwing an error. The one that doesn't throw an error is the one that exists in the same exact folder as the vpch.h. So files that can't just write #include "vpch.h" and have to write something like "../vpch.h" I can write #include <vpch.h> and I am going to try that now but I am unsure that will help.
The issue was with every CPP file that wasnt in the same folder as the precompiled header.
So if you use a file structure that contains different classes in different folders, using
#include "../../vpch.h" will actually fail. You must add the root folder to your additional include directories and then use #include <vpch.h> for all files. I can NOT tell you why using #include "../../vpch.h" wasn't working. It seems counter intuitive for it to fail in my opinion.
It may be because it searches for the precompiled header in the same folder as the file you are referencing it in. This answer, however, will work as a solution.
I'm in VS2013, C++ console applications. I'm having a problem integrating boost into a large framework. If I try integrating them in a blank console application, they work fine. Once I include the "root" .h file of the framework (that includes "many" other .h files in the bargain), it breaks. These .h files are "polluting" the boost ones (and anything included after, with mixed results, and no, I can't just include boost ones first, that's not always an option unfortunately). I've found at least one root-level #define that interfered and caused a compile error, but I can't find some of the other conflicts that are causing run-time problems.
Specifically, my problem is this: how do I tell what symbols have been defined by .h files? And hopefully, which ones are then conflicting later? I tried googling, but couldn't find a tool for doing this.
Or is there some other method which can "isolate" them (my problem .h files), and yet still have them link correctly to the functions they're calling in other .dlls?
You can use g++ -E as a static code checking tool (without changing your toolset). It is able to tell you when something is redefined but not when a #define is used as another name (it would have no way to tell whether it was a real substitution or not).
If that's not the source of your problem then you may need to take a more holistic approach: Start changing your project's #define use to other constructs such as const and short functions. This will then allow the compiler to either resolve differences by overloading or complain that there are conflicts.
Including same header file again might have caused the problem,you can create a symbol for each header file so that if that header file is already included in some other header file it shouldn't be included.
#ifndef
#define __header_file_name_H
.....some code
#endif
I'm compiling some code that relies on include guards to prevent multiple definitions of objects and functions, but Visual Studio 2008 is giving me link errors that there are multiple definitions. I don't understand why because I've used code very similar to this before and it hasn't caused problems. I must be doing something dumb but I have no idea what it is. I also tried to take out the include guards and use #pragma once, but I get the same link errors. What should I check for?
If they are linker errors, the most likely cause is probably non-inline functions defined in the header.
If you have a non-inline function in a header that is included in more than one source file, it will be defined in each of those source files ("translation units"), thus the function will be defined more than once, hence the multiple definitions error.
If you're getting linker errors... are you sure you're not 1) actually defining a function twice in code or 2) trying to do something silly like #include a source file (as opposed to a header file)?
This can also be caused by using different versions of the cstd lib from other library's linked in. Check under the c++/Code generation section and make sure all your projects are using the same settings.
I'm compiling a project in XCode where MySQL++ in included and linked to. For some reason, I keep getting the following compiler error:
'assert’ was not declared in this scope
originating from cpool.h, a header file that's part of MySQL++. Does anyone know why this is being triggered?
EDIT: For reference, MySQL++ was installed via Macports.
The most obvious answer would be that "assert.h" is not being included or is not being found in your include path. Another explanation is that the assert macro has been undefined at some point after the header was included.
Edit: Since you say that assert.h is included, and we'll assume for the moment that it's being found since it's a standard header, then that leaves us with the last possibility I stated above i.e. that the macro has been undefined.
Since cpool.h itself will not be doing this it must be the case that assert.h is included earlier either by yourself or indirectly by another 3rd party header and the undefining happening between this and your inclusion of cpool.h. This can easily be tested by moving your cpool.h include to the top of your file.
In c++ adding cassert header should fix your problem.
#include <cassert>
It could be that another library in your include path has a different "assert.h" file, and you are unknowingly including that one instead of the system's standard <assert.h>.
I ran into this issue when writing an application that uses gstreamer on Mac OSX. It turns out that gstreamer's include directory (/Library/Frameworks/GStreamer.framework/Headers) includes a file "assert.h", which is non-standard and an unsuitable replacement for the real assert.h. When I added -I/Library/Frameworks/GStreamer.frameworks/Headers to my compilation command, suddenly my sources, which just said "#include <assert.h>" where including the gstreamer version. This caused my compilation to fail with the same error you were getting.
while programming in c++,
Most of the times i get 'some symbol' has already been defined
see previous definition of 'some symbol'
I think this happens because improper order of headers file included.
How can i find out all the definitions of 'some symbol'
Thanks in advance,
Uday
EDIT:
I am using visual studio
I remember some command some thing like dumpbin /exports (I dont remember exactly) to get all the definition
That usually happens due to a couple of common problems:
you are redefining the same symbol
you are including a header file many times and it does not have include guards
you are incorrectly forward declaring with an incompatible type and then including
I would start trying to fix the second. Make sure that all headers have include guards so that if you include them from different places it won't try to redefine the symbols:
#ifndef HEADER_FILE_NAME_GUARD // or something alike
#define HEADER_FILE_NAME_GUARD
// rest of file
#endif
If you need to order your includes then you will run into troubles later, make sure that you can and do include all your dependencies at all places. (Or forward declare if you can)
Full-text search is the most cross-platform cross-environment and efficient technique for that.
Translating C++ into an executbale has two steps. In step one, the compiler works linearly through the inputs (typically .cpp files and the headers they include). In step 2, the linker combines the results from step 1.
From your description of "symbol defined before", I conclude the problem must occur within a .cpp file, as those are processed linearly. dumpbin /exports works on the output of step 1, which you probably won't have. Header inclusion could be the culprit, as that's an early phase of compilation. You want the preprocessed input. IIRC, you can get that with the /EP switch.
If you're using Visual Studio with Visual Assist installed, alt-G will pop up a list of all places where something is defined.
If you're using Visual Studio with Visual Assist installed, you'd better press Alt+X then D to see all the references to the symbol
If you need to order includes, it is an indication of 'Code Smell' in the first place. Most probably, your code is not designed well enough. All your common code should be part of a separate package/dll/lib(whatever) and should be included/linked from there.
If you are in C++/VC++, this normally happens when you include cpp & h files directly from other projects instead of linking to a utility library of some sort.
As somebody already pointed out, if you have to live with it, text search is the best option but try re-designing the code in a better way (if you can).
Generally I just grep the header files.