I'm working with a file that uses the PIP_ADAPTER_ADDRESSES type. The person who worked on this code was using VS2013 (my current job is to upgrade the codebase to VS2017). The #includes look like this:
#include <winsock2.h> // Include for security.h
#include <security.h> // Include for EXTENDED_NAME_FORMAT
#include <iphlpapi.h> // Include for PIP_ADAPTER_ADDRESSES
And I get error C2061: syntax error: identifier 'PIP_ADAPTER_ADDRESSES' when trying to compile. This appears to be a problem in VS2017 but not VS2013.
PIP_ADAPTER_ADDRESSES appears to be defined in <IPTypes.h>, which is included by <iphlpapi.h>, but it is inside an #ifdef _WINSOCK2API_ block. However, this should be defined since I included <winsock2.h>. What's going on here?
Edit: On second glance, it looks like that error message doesn't indicate that it's undefined, but rather that there is a circular dependency with this identifier. I am continuing to investigate.
It turns out that in my case there was ANOTHER file that had included <iphlpapi.h> but not <winsock2.h>, which was causing the errors in the file I was working on. For some reason, this file was being compiled first in VS2017 but not in VS2013. Make sure you check all of your includes, I guess.
I faced to similar problem. When WinSock2.h header file is not included, then PIP_ADAPTER_ADDRESSES is not declared. If WinSock2.h is included, then a lot of error messages are generated.
So, thanks to this answer, I investigated the WinSock2.h header file and I found this comment:
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
I changed the order of the include files moving Windows.h after WinSock2.h and iphlpapi.h and this solved the issue.
Related
I am using CMake with Visual Studio and I keep getting the error yvals_core.h(23): fatal error C1189: #error: STL1003: Unexpected compiler, expected C++ compiler.
This error only happened after I moved all my includes to my precompiled header. It looks like the __cplusplus macro is not defined for some reason.
More information: I just have a header file including all the includes I need. Then I just added that header file to the precompiled header by using target_precompile_headers
I have recently experienced the same issue.
I noticed that the iostream.h library used for C++ was included in a .c file within my program. Once I removed this include directive (#include <iostream.h>) the error was resolved.
Check all the include directives within the program and verify them for correctness. Please let me know if this helps.
I got this error in MS Visual Studio 2022 with a C project that mistakenly included <iostream>
Removing this fixed the issue.
I beg your pardon if this question has been already answered, but I have been trying to implement precompiled headers in my game engine with no success so far.
My precompiled header is called UtilBase.h:
#pragma once
#if !defined(NF3D_UTIL_BASE_H)
#define NF3D_UTIL_BASE_H
// This is a precompiled header.
#pragma message("Compiling precompiled header.")
// Include engine specific files.
#include <Utilities\Platform\Types.h>
// Include external header files (STL, Win32 API, Direct3D 11, etc)
// There are some typedefs here:
typedef __int32 int32; // And so on.
#endif
Although this is against the standards, I included UtilBase.h in other headers because I need access to some of its contents. It is also included in all .cpp files, first line, from the current project (the solution has two projects).
I need it in some headers because it stores some typedefs that are used in function declarations. For example, I have some file called Window.h:
#pragma once // And include guards that are omitted here
int32 NF3DCreateWindow();
The associated source file is called UtilBase.cpp and has only one line of code:
#include <Utilities\UtilBase.h>
The project has been set up correctly in my opinion:
for all platforms and configurations.
UtilBase.cpp has this setting:
However, when I compile I get this error:
1>Source Files\Utilities\UtilBase.cpp(2): error C2857: '#include' statement specified with the /YcD:\New Frontiers\NewFrontiers3D\Header Files\Utilities\UtilBase.h command-line option was not found in the source file
which points to the only line in UtilBase.cpp (#include <Utilities\UtilBase.h>).
Why does this happen and what can I do to make it work? I will gladly send any further information about this scenario. Thank you very much in advance.
Finally made it! For anybody in my situation here is what I did: in project settings, Precompiled Header File tag, I added $(ProjDir)\Header Files\Utilities\UtilBase.h and it was evaluated to the full path of the file. The correct way is to simply add the file: Utilities\UtilBase.h and that's it.
Thank you for your support.
try #ifndef instead of #if !defined
the first error when putting #include <afxinet.h> in a header file
IntelliSense: #error directive: WINDOWS.H already included. MFC apps must not #include <windows.h>
(1) Any idea why this is it?
The other similar thing is if you put the headers in a wrong order, odd errors appear, whose msg do not make sense at all... this kind of behaviour of VC++ complier is driving me crazy.
(2)anyone has a solution to this kind of problem?
I had similar problem with winsock.h, something like that:
fatal error C1189: #error : WinSock.h has already been included
I've added the WIN32_LEAN_AND_MEAN preprocessor directive to my project and it fixed it.
I can't tell why, or what is the reason behind that.
I'm trying to include secExt.h in my C++ project and it gives me the error:
error C2086: 'BOOLEAN SEC_ENTRY' : redefinition
How can I fix it?
EDIT: from microsoft's docs, include security.h, not [secext.h].
original answer (before I googled the header name myself, no info given by OP):
if the header is yours, add
#pragma once
at the top.
if that doesn't work (there is reportedly a compiler on some IBM system or something that doesn't support #pragma once), then use a header guard.
if the header isn't yours, create a header wrapper like this:
#pragma once
#include <secExt.h>
then include your wrapper header instead of including [secExt.h] directly.
When I include winsock2.h, I get about 60 redefinition errors. I hunted around a bit a found some advice to include winsock2.h b4 including windows.h. I did that and that cleared up the errors. My problem and question concerns exactly how I should go about doing this. I did not explicitly include windows.h, it was done for me in stdafx.h or stdafx.cpp.
I added the include winsock2.h immediately b4 the include Windows.h in stdafx.h. Is this the right way to go about this or is there a better way?
Judging by a comment in program_name.rc I gather the windows.h include in stdafx.h may have been placed there as a result of some option or configuration parameter but I was unable to find this reference. Is there some way to specify what files are included in stdafx.h?
BTW, WIN32_LEAN_AND_MEAN was defined b4 calling windows.h in stdafx.h.
I am using Visual c++ 6.0 and 'Windows Server 2003 PSDK' The program is straight c++, no mfc, no net, just plain vanilla.
You can put pretty much whatever you want into stdafx.h. It's certainly fine to add your #include for winsock2.h before the windows.h. I'd move the WIN32_LEAN_AND_MEAN header so that it's defined before you include any other headers:
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
stdafx.h is a horrendous name for the precompiled header. I have no idea why Visual Studio still uses this for all the autogenerated projects. It gives the precompiled header an undeserved air of mystery. In my projects I usually set up the precompiled header to use 'precompiled.h' and 'precompiled.cpp'.
Noel Llopis has a great article on precompiled headers - 'The Care and Feeding of Precompiled Headers' if you want a bit more background info on what's going on here.
That should work okay. If you look in winsock2.h, you can see that it includes windows.h if it hasn't already been included.
You need to make sure that WinSock2.h is included BEFORE windows.h, make sure that wherever you're including WinSock2.h, it is included before stdafx.h and/or windows.h