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.
Related
I'm using precompiled headers in my Visual Studio (2019) C++ project, and am including "pch.h" at the top of my source files, have #pragma once at the top of each header file, and a pch.cpp file (generated by the project template). Yet for one of the source files I get compiler error C1010: "Unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?" What other causes are there for this error?
In my case, I had a corrupt cpp source file (a different one from where the error was occurring), caused by an earlier sudden power failure. It seems that once I recreated the corrupt file, the project was back into a valid state and the error went away the next time I built. ...It was a bit of a corner case, but you might clean/rebuild and check that nothing is corrupt.
I am trying to use Visual Leak Detector in my C++ application (using visual studio 2013), and after reading the documentation and modifying Include Directories and Library Directories of a project, I am adding vld.h header in one of my cpp files. As written in the documentation I have to add it after all the precompiled headers in the source. But while building the project after adding the header in my source code I am getting following error:
[VLD COMPILE ERROR] #include "vld.h" should appear before #include <afxwin.h> in file stdafx.h
so when I add it in the stdafx.h header file, the project builds but I get a runtime error saying:
Unhandled exception at some_memory_location (vld_x64.dll) in product_debug_build.exe. Access violation reading location some_memory_location
And when I put it before precompiled headers in any of my cpp files, then the build skips the inclusion of the header file vld.h.
But I don't get this message when I build the whole solution, but then it doesn't work (probably because I am adding it before precompiled headers ?).
What am I doing wrong here?
I'm working with an API which has #defineed all their include files. I'm developing in Visual C++ 2010 Express, and it's been working fine up till now.
I was adding a new cpp-file to the project, and accidentally added a "Windows Form" instead. VC warned me that my project was not using CLR at the moment, did I really want to? I clicked no, and added the file as intended. After that, however, my project no longer compiles.
The code looks basically like this:
api_header.h:
#define DEFINED_HEADER_NAME "path/to/header/file.h"
stdhpf.h:
#include DEFINED_HEADER_NAME
As I said, worked fine for a long time. Now I get this:
error C2006: '#include' : expected a filename, found 'identifier'
fatal error C1083: Cannot open include file: '': No such file or directory
What is causing this? I found some post that said it was because of having turned on precompiled headers, but I checked Project properties > Configuration properties > C/C++ / Precompiled headers, and it's off (I mention the setting path since I'm new to VS, there might be more than one way to do it...).
Any ideas?
The problem almost certainly lies in the order in which the two statements are pre-processed, rather than having anything to do with inadvertently adding a Windows Form object.
This knowledge base article suggests:
The problem is in using a defined constant to specify an include file in the #include directive. The directive is being processed before the macro is completely expanded, resulting in the error.
The second error seems to confirm this, as it indicates the pre-processor is searching for an include file with an empty name:
fatal error C1083: Cannot open include file: '': No such file or directory
The order of your include files has changed. Perhaps Visual Studio inserted a #include "stdhpf.h" somewhere ahead of your #include "api_header.h".
Disable precompiled headers. It should helps.
I'm trying to pull libcurl into a large C++ project.
However I am having trouble getting it to compile. I see errors coming from ws2def.h, winsock2.h, and ws2tcpip.h
Some of the errors look like this:
error C2061: syntax error : identifier 'iSockaddrLength' ws2def.h 225
error C3646: 'LPSOCKADDR' : unknown override specifier ws2def.h 225
..
error C2061: syntax error : identifier 'dwNumberOfProtocols' winsock2.h 1259
I tried compiling the file that #include "curl.h" in straight C mode, but that did not fix the problem.
Which C++ compiler are you using? Mine does not have ws2def.h at all. Also, keep in mind that winsock.h and winsock2.h are not compatible with each other, and some of the Win32 header files will include winsock.h by default, before your code has a chance to include winsock2.h. So you may have to disable winsock.h by defining _WINSOCKAPI_ in your project's compiler conditionals.
Try including windows.h BEFORE you include winsock2.h or any libcurl headers. Don't ask my why this sometimes works, but it does.
It kinda looks like something else is bringing in winsock defines that are conflicting with curl. Can you try to set up a project that just uses curl? Oh, an I had to add CURL_STATICLIB to my preprocessor definitions to make it link.
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.