Reputation: 4820
I'm trying to compile an unspecified piece of software, and I'm getting errors in the standard headers such as stdio.h
. The errors are mostly undeclared identifiers such as _In_
. IntelliSense finds their definitions just fine. In what general direction should I look for the cause of this?
Added: For example, in one cpp file stdio.h
is the first file included - there are no defines that I can see before it. No precompiled headers are used. Other stuff on my install compiles just fine.
Upvotes: 1
Views: 8256
Reputation: 2839
This happened to me today, and it took me four frustrating hours to to solve it, even after looking for answers in this forum, so let me post my problem and its solution in case it occurs again for anyone else.
I had this (in slightly less obvious form):
namespace MyApp
{
#include "MyUtilities.hpp"
};
#include "MoreUtilities.hpp"
Both MyUtilities.hpp
and MoreUtilities.hpp
included <wait.h>, but the second attempt (by the library) to use standard system type sigval_t
inside MoreUtilities.hpp threw a compiler error (in the standard library). As for the original poster, this was the first error found by the compiler; for me, it produced an irritating "Type not found" error, which seemed obviously wrong given that it is a standard type and it was "not in my code."
The second inclusion of <wait.h> generated no new code, because the definitions had already been made. However, they were not found by the compiler due to being in a different namespace.
The solution, of course, is to be sure to #include <standard-header.h>
outside of all local namespace declarations.
Upvotes: 0
Reputation: 9003
I think sometimes mismatch between different versions of headers library can cause this as well. Have you recently install new versions of standard libraries, like with SDK or whatever, or played with the PATHs and stuff like that?
Upvotes: 0
Reputation: 20039
The errors are mostly undeclared identifiers such as
_In_
. IntelliSense finds their definitions just fine. In what general direction should I look for the cause of this?
An undeclared identifier probably means that your standard header is itself trying to include
another header (internally), not finding it, and therefore not getting identifiers properly declared/defined.
Added: For example, in one cpp file stdio.h is the first file included - there are no defines that I can see before it.
A define
is different from a declaration, which is different from a definition. You probably already know this, but I just want to be sure.
Since the question is tagged as C++, I would encourage you to include
cstdio
instead of stdio.h
. It probably won't fix the compiler error, but it's the official C++ header. On POSIX systems you'll sometimes find that the standard C headers get extended with things from POSIX. In my experience you don't have the same extensions in the C++-ified versions of those headers.
Upvotes: 0
Reputation: 23377
Possibilities:
Best diagnostic is to dump preprocessed source. Every compiler has an option for this. I believe it's -E on gcc, check the docs or gui options for visual studio.
Upvotes: 2
Reputation: 43356
Since VS likes to use precompiled headers, you might want to make sure that you haven't violated any of the assumptions. One source of trouble is to name any header at all ahead of the line that includes stdafx.h
.
Even in the without any precompiled headers issues, you might be inadvertently defining something that interacts badly with definitions in the stock headers. If you look inside stdio.h, you'll see that it has a number of interesting conditional compilation sections since the same file is distributed to a number of distinct platforms. Be sure to look at your project's settings, and if the issue is happening only when compiling a specific source file, then that file's compilation settings as well.
It is certainly worth starting a new project and checking if good ol' hello.c can be compiled...
#include <stdio.h>
int main(int argc, char **argv) {
printf("hello, world.\n");
return 0;
}
if not, then there is something seriously wrong with your VS installation.
One other possible but unlikely source of trouble would be if you have other compilers installed, and have somehow accidentally got VS using another stdio.h
entirely... An inappropriate INCLUDE environment variable used to be able to cause that, but I'm not certain it does in recent versions. I got burned by that a long time ago, and have been much more careful about what variables I let individual compilers set in the global environment since then.
Upvotes: 2
Reputation: 43116
The standard line should compile. However, if you have modified or deleted some files in the headers provided with the Visual Studio installation, you are in troubles and will have to reinstall everything.
One way to make sure is to make a a new "hello world" console application. It will include stdio in the stdafx.h.
I don't think that this is your problem and you should give more details about the problem if you want a better answer.
Is the stdio included in the stdafx.h?
Upvotes: 0
Reputation: 248119
"You're doing something unspecified wrong" is about the best I can do.
The standard library does compile, I can tell you that much.
So either your project configuration is wrong, or something in your code affects the included file (perhaps some bad #defines, for example)
If you want a more specific answer, you'll have to give us some specific information. Which errors are you getting? How is the file included? Can you show some minimal code that reproduces the problem?
Upvotes: 6