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.
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 have begun writing a little C++ recently, and I decided to write a Qt program as an introduction, since I already know many of the function names etc. I have a file that gets the Jumbo icons using some win32 api. To use this I have the following includes:
#include <commoncontrols.h>
#include <shellapi.h>
#include <CommCtrl.h>
//other include statements for Qt
I keep getting an error
C:\Program Files (x86)\Windows Kits\8.1\Include\um\commoncontrols.h:198: error: C2061: syntax error : identifier 'IMAGELISTDRAWPARAMS'
and
C:\Program Files (x86)\Windows Kits\8.1\Include\um\commoncontrols.h:212: error: C2061: syntax error : identifier 'IMAGEINFO'
How could the error be in commoncontrols.h? As I understand it, the compiler cannot find a reference to those structs since CommCtrl is included after commoncontrols. So I reversed their include positions, thinking that would solve the problem, but that caused 127 other errors, so it seems not the correct direction. I am using Qt creator with Qt 5.4.1 and I am on Windows 8.1, so I am using the windows SDK for that. The kit is x64, since I am using the MSVC x64 compiler in VS 2013.
What am I doing wrong and why is it wrong?
You have a circular dependency problem. You didn't provide much information about the other header files.Example;
Header A.h might depend on header B.h and header B.h depend on header A.h.
You mostly solve this problem by replacing #include "A.h" in header B.h with a forward declaration of header A.h like so; class A in header B.h or vice versa.
I have set up a project in Visual Studio to create a .dll. I have included an external library in the project which uses the keyword "interface". This is giving me the following error:
error C2146: syntax error : missing ';' before identifier 'INuiAudioBeam'
These are the lines of code where the error occurs:
#ifndef __INuiAudioBeam_FWD_DEFINED__
#define __INuiAudioBeam_FWD_DEFINED__
typedef interface INuiAudioBeam INuiAudioBeam; //Error on this line
#endif
The above code is part of a header file in the external library I have included. The project builds successfully without any errors when compiling without including the headers for the library (Note: Linking the library does not cause any problems).
What is the solution to this? Is it because I have an external library I'm using to create my dll? Should I create a .lib instead of a dll?
If anyone else searches this, the problem is most likely
#define WIN32_LEAN_AND_MEAN
Before
#include <windows.h>
Remove the define, make sure your including windows.h, and that should define interface keyword for you
You can get C2146 with indictment of the interface keyword. It may be confusing as to how a keyword may be undefined, especially that in other compilation units or projects that use the same header file - the inclusion of which brought about the problem - all goes smooth. However, the apparent keyword "interface" is still a compiler #define directive. It just happens to be buried inside a header file that a few developers have reasons to inspect: the <objbase.h>. There it is defined in two steps:
#define __STRUCT__ struct
#define interface __STRUCT__
Since the <objbase.h> is included by multiple other header files - such as ole2.h, oleauto.h, and a slew of ATL headers - you may be surprised with this error when none of those headers were included in the current compilation unit.
Using MSVC2008, 32bit on 64bit system.
I was once advised to never include windows.h as 'its a real monster and will slow down my compile times significantly'.
I tried leaving it out and obviously get compile errors. I included windef.h to define all the DWORDs etc, but I quickly come unstuck knowing what else to define to get the code to compile.
I now get:
2>c:\program files\microsoft sdks\windows\v7.0\include\winnt.h(6361) : error C2146: syntax error : missing ';' before identifier 'ContextRecord'
2>c:\program files\microsoft sdks\windows\v7.0\include\winnt.h(12983) : error C2065: 'PCONTEXT' : undeclared identifier
Can anyone suggest the right approach here?
Thanks
Simon
Use precompiled headers to improve compile times, and include windows.h.
Internally, windows.h respects many defines, like NOMINMAX or WIN32_LEAN_AND_MEAN.
It reduces the times significantly.
The correct answer would be "include it in the PCH". Pre-compiled headers reduce compilation time dramatically, and, contrary to popular belief, this is true also for Full Rebuilds.
If you have more than one CPP file in your project, the "Rebuild all" would build it once for the whole project, which merely ads a few seconds to compile time - to have windows.h included in all of them.
Research the APIs and make sure the headers are included in the correct order. It's not hard to not use Windows.h; but you'll learn about the MS headers in the process.
There are a few headers you have to be aware of:
WTypes.h
WinDef.h
WinBase.h
WinObject.h
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.