Windows Forms application lots of ambiguous symbols - winforms

Creating a c++ forms application, I have started getting some ambiguous symbol errors. But I am not quite sure what from, it was compiling fine earlier but I may have changed something?
Thee error itself:
1>Application.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could be 'IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): note: or 'System::Windows::Forms::IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): error C2872: 'IServiceProvider': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\servprov.h(98): note: could be 'IServiceProvider'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): note: or 'System::IServiceProvider'
1>main.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could be 'IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): note: or 'System::Windows::Forms::IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): error C2872: 'IServiceProvider': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\servprov.h(98): note: could be 'IServiceProvider'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): note: or 'System::IServiceProvider'
I found this strange because my form isn't contained with any of these files, I assume it's that due to the namespacing. I just don't know where this is actually coming from.
Here is my form for info:
#include <Windows.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class CFormController : public Form
{
public:
CFormController(void)
{
InitializeComponent();
}
~CFormController()
{
delete components;
}
System::ComponentModel::Container ^components;
void InitializeComponent(void)
{
this->components = gcnew System::ComponentModel::Container();
this->Size = System::Drawing::Size(300, 300);
this->Text = L"FormController";
this->Padding = System::Windows::Forms::Padding(0);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
};
The only other information about my form is in another class. Thats only used to display or hide it.
I found similar issues in that people didn't include the windows header before "using namespace..." but I added the include as you saw and it didn't make a difference whatsoever

You are importing conflicting symbols into the global namespace.
The code you posted should fine if it is the first file included in the compile unit. If that is not the case (e.g. you included another header file before the header file you posted) they you could have the WinForms types already present in the global namespace when you include windows.h, and causes C2872.
You can move the using statements or windows.h include into a namespace to avoid the conflict.
e.g.
namespace Win32 {
#include "windows.h"
}
or
namespace ProjectName {
using namespace System;
......
}
Or if you really want to import the types into the global namespace, separate your code into two cpp files and import them one at a time.

C++/CLI is notorious for symbol conflicts, whenever you are "using" many C# namespaces. Obviously, you have a conflict between System and System::Windows::Forms. Try to remove the latter "using" declaration, and specify symbols from this namespace by prefixing them with System::Windows::Forms::. I know this is a royal pain, but as far as I know there's no other workaround.
I face this problem regularly whenever I need classes from System::Collections::Generic.

Related

#include <dwrite.h> in C++ works, but not in C

A single-line test.c:
#include <dwrite.h>
From the visual studio command prompt,
compiled as C++ works: cl /c /Tp test.c
compiled as C does not: cl /c test.c
First, I get a bunch of errors as this one:
C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um\dwrite.h(671): error C2059: syntax error: ':'
The line 671 is as follows:
interface DWRITE_DECLARE_INTERFACE("739d886a-cef5-47dc-8769-1a8b41bebbb0") IDWriteFontFile : public IUnknown
preprocessed to C++
struct __declspec(uuid("739d886a-cef5-47dc-8769-1a8b41bebbb0")) __declspec(novtable) IDWriteFontFile : public IUnknown
preprocessed to C
struct IDWriteFontFile : public IUnknown
and the part " : public IUnknown" gets in the way.
How am I supposed to fix this?
Then I get an error on line 1037: error C2061: syntax error: identifier 'IDWriteGeometrySink'
interface ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
preprocessed to C
struct ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
Finally, a bunch of errors involving static_cast which C does not have.
All in all, is dwrite.h not suitable for C? Using Visual Studio Community 2022. Does it work in any previous versions?
What I'm trying to do is compile https://github.com/makuke1234/PongD2D
C doesn't have inheritance, so this header is most likely C++ only.
The project you linked uses D2D from .cpp files and wraps C++ interface into C.

LNK2019 unresolved external symbol _GetExtendedTcpTable#24 [duplicate]

During coding in Visual Studio I got an unresolved external symbol error
and I've got no idea what to do. I don't know what's wrong.
Could you please decipher me? Where should I be looking for what kind of errors?
1>Form.obj : error LNK2019: unresolved external symbol "public: class Field * __thiscall Field::addField(class Field *)" (?addField#Field##QAEPAV1#PAV1##Z) referenced in function "public: void __thiscall Form::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse#Form##QAEXAAV?$basic_stringstream#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>Form.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall Field::parse(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?parse#Field##UAEXAAV?$basic_stringstream#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall InputField::InputField(class std::basic_stringstream<char,struct std::char_traits<char>,class std::allocator<char> > &)" (??0InputField##QAE#AAV?$basic_stringstream#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::prompt(void)" (?prompt#Field##UAEXXZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getName(void)" (?getName#Field##UAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Field::getType(void)" (?getType#Field##UAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ)
1>Form.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Field::describe(void)" (?describe#Field##UAEXXZ)
1>C:\Users\tomy\Documents\Visual Studio 2010\Projects\zapoctovkac++\Debug\zapoctovkac++.exe : fatal error LNK1120: 6 unresolved externals
This error often means that some function has a declaration, but not a definition.
Example:
// A.hpp
class A
{
public:
void myFunc(); // Function declaration
};
// A.cpp
// Function definition
void A::myFunc()
{
// do stuff
}
In your case, the definition cannot be found. The issue could be that you are including a header file, which brings in some function declarations, but you either:
do not define the functions in your cpp file (if you wrote this code yourself)
do not include the lib/dll file that contains the definitions
A common mistake is that you define a function as a standalone and forget the class selector, e.g. A::, in your .cpp file:
Wrong: void myFunc() { /* do stuff */ }
Right: void A::myFunc() { /* do stuff */ }
Check you are including all the source files within your solution that you are referencing.
If you are not including the source file (and thus the implementation) for the class Field in your project it won't be built and you will be unable to link during compilation.
Alternatively, perhaps you are using a static or dynamic library and have forgotten to tell the linker about the .libs?
It looks to be missing a library or include, you can try to figure out what class of your library that have getName, getType etc ... and put that in the header file or using #include.
Also if these happen to be from an external library, make sure you reference to them on your project file. For example, if this class belongs to an abc.lib then in your Visual Studio
Click on Project Properties.
Go to Configuration Properties, C/C++,
Generate, verify you point to the abc.lib location under Additional
Include Directories. Under Linker, Input, make sure you have the
abc.lib under Additional Dependencies.
I've just seen the problem I can't call a function from main in .cpp file, correctly declared in .h file and defined in .c file. Encountered a linker error. Meanwhile I can call function from usual .c file. Possibly it depends on call convention. Solution was to add following preproc lines in every .h file:
#ifdef __cplusplus
extern "C"
{
#endif
and these in the end
#ifdef __cplusplus
}
#endif
I had an error where my project was compiled as x64 project. and I've used a Library that was compiled as x86.
I've recompiled the library as x64 and it solved it.
sometimes if a new header file is added, and this error starts coming due to that, you need to add library as well to get rid of unresolved external symbol.
for example:
#include WtsApi32.h
will need:
#pragma comment(lib, "Wtsapi32.lib")
I had the same link errors, but from a test project which was referencing another dll. Found out that after adding _declspec(dllexport) in front of each function which was specified in the error message, the link was working well.
Yet another possible problem (that I just scratched my head about for some time):
If you define your functions as inline, they—of course!—have to be defined in the header (or an inline file), not a cpp.
In my case, they were in an inline file, but only because they were a platform specific implementation, and a cpp included this corresponding inl file… instead of a header. Yeah, s**t happens.
I thought I'd leave this here, too, maybe someone else runs into the same issue and finds it here.
This error can be caused by putting the function definitions for a template class in a separate .cpp file. For a template class, the member functions have to be declared in the header file. You can resolve the issue by defining the member functions inline or right after the class definition in the .h file.
For example, instead of putting the function definitions in a .cpp file like for other classes, you could define them inline like this:
template<typename T>
MyClassName {
void someFunction() {
// Do something
...
}
void anotherFunction() {
// Do something else
...
}
}
Or you could define them after the class definition but in the same file, like this:
template<typename T>
MyClassName {
void someFunction();
void anotherFunction();
}
void MyClassName::someFunction() {
// Do something
...
}
void MyClassName::anotherFunction() {
// Do something else
...
}
I just thought I'd share that since no one else seems to have mentioned template classes. This was the cause of the error in my case.
In addition to the excellent answer by Chris Morris above, I found a very interesting way you can receive this same fault if you are calling to a virtual method that hasn't been set to pure but doesn't its own implementation. It is the exact same reason (the compiler can't find an implementation of the method and therefore crooks), but my IDE did not catch this fault in the least bit.
for example, the following code would get a compilation error with the same error message:
//code testing an interface
class test
{
void myFunc();
}
//define an interface
class IamInterface
{
virtual void myFunc();
}
//implementation of the interface
class IamConcreteImpl
{
void myFunc()
{
1+1=2;
}
}
However, changing IamInterface myFunc() to be a pure virtual method (a method that "must" be implemented, that than a virtual method which is a method the "can" be overridden) will eliminate the compilation error.
//define an interface
class IamInterface
{
virtual void myFunc() = 0;
}
Hopes this helps the next StackOverFlow person stepping through code!
I believe most of the points regarding the causes and remedies have been covered by all contributors in this thread. I just want to point out for my 'unresolved external' problem, it was caused by a datatype defined as macro that gets substituted differently than expected, which results in that incorrect type being supplied to the function in question, and since the function with type is never defined, it couldn't have been resolved. In particular, under C/C++ -> Language, there is an attribute called 'Treat WChar_t As Built in Type, which should have been defined as 'No (/Zc:wchar_t-)' but did not in my case.
I just had a hard time with this. Everything was logically set up. I declared a constructor but didn't define it
class SomeClass
{
SomeClass(); // needs the SomeClass::SomeClass(){} function defined somewhere, even here
}
I almost banged my head on my keyboard when I forgot something so elementary.
See Linker Tools Error LNK2019 at MSDN, it has a detailed list of common problems that cause LNK2019.
Make sure you decorate your header files with
#ifndef YOUR_HEADER_H
#define YOUR_HEADER_H
// your header code here
#endif
Bad things -including this- can happen if you don't
I'm doing some C++ for the first time in a long time, and I'm getting this error when I forget to add the ClassName:: prefix for the function definition, since this is a little unique to C++. So remember to check for that too!
POINTERS
I had this problem and solved it by using pointer. I see that this wasn't your issue but I thought I'd mention it because I sure wish it had been here when I saw this an hour ago. My issue was about declaring a static member variable without defining it (the definition needed to come after some other set ups) and of course a pointer doesn't need a definition. Equally elementary mistake :P
One possible cause of this linker error can also be inline functions that are declared but not defined in a header file that is then included somewhere else. Inline functions have to be defined in every translation unit they are used in.
Make sure that you are not trying to overload the insertion or extraction operators as inline functions. I had this problem and it only went away when i removed that keyword.
What had caused it in my case:
I had a huge file Foo.cpp without a Foo.h. Foo.cpp began like this:
// ... 100 LOC here ...
namespace NS {
// ... 100 more LOC here ...
static int var;
I removed the "static" keyword and added a Foo.h with this:
extern int var;
Do you see the mistake?
I totally missed that var was originally defined in a namespace, because the namespace declaration was buried in other code. The fix is to change the extern like this:
namespace NS {
extern int var;
}
In my case, I needed add the function name to the DEF file.
LIBRARY DEMO
EXPORTS
ExistingFunction #1
MyNewFunction #2
My issue was a sconscript did not have the cpp file defined in it. This can be very confusing because Visual Studio has the cpp file in the project but something else entirely is building.
My issue was: I had to do forward declaration of the class whose ctor was "unresolved external".
In the file where I got the error, I had to put something like this:
#include "ClassB"
class ClassB; // this solved the problem
class ClassA{
void foo(){
ClassB* tmp = new ClassB();
// ...
}
};
Of course, my project is much more complicated and this is just a snippet example. Also when using namespaces, declare them as well.
Just spent a couple of hours to find that the issue was my main file had extension .c instead of .cpp
:/
Yet another possibility to check, it was my problem this time.
I had added the function to the library, and included the library's output folder in the search path.
But I also had a folder with an older version of the library listed before, so VS was using the old library, and of course not finding the new function.
A possible reason for the "Unresolved external symbol" error can be the function calling convention.
Make sure that all the source files are using same standard (.c or .cpp), or specify the calling convention.
Otherwise, if one file is a C file (source.c) and another file is a .cpp file, and they link to the same header, then the "unresolved external symbol" error will be thrown, because the function is first defined as a C cdecl function, but then C++ file using the same header will look for a C++ function.
To avoid the "Unresolved external symbol error", make sure that the function calling convention is kept the same among the files using it.
I came here looking for a possible explanation before taking a closer look at the lines preceding the linker error. It turned out to have been an additional executable for which the global declaration was missing!
I faced a similar issue and finally managed to solve it by adding __declspec(dllimport) to the declaration of the class:
// A.hpp
class __declspec(dllimport) A
{
public: void myFunc();
// Function declaration
};
In my case I had multiple namespaces in my header file without nesting (one after the other) however in my source file I had accidentally nested one of the namespaces inside another:
// myExample.h
#ifndef MYEXAMPLE_H
#define MYEXAMPLE_H
namespace A
{
void aFunc();
}
namespace B
{
void bFunc();
}
// myExample.cpp
#include "myExample.h"
namespace A
{
void aFunc()
{
...
}
namespace B // whoops! I nested this inside namespace A when I didn't mean to.
{
void bFunc()
{
...
}
}
}
// main.cpp
#include "myExample.h"
int main()
{
myExample::B::bFunc();
return 0;
}
When I used F12 to "Go to definition" on the function in Main, Visual Studio found the code in the source file even though it was declared in a deeper namespace by accident.
Debugging Technique
I spotted the issue when renaming the function while trying to debug the issue. The rename preview window showed an "External References" node with the function inside the source file clearly nested under another namespace by accident.
I had the same issue. Mine was working one day and then not the next day after I pulled the latest code.
The latest code did not include the project I was referencing in my library. So when I rebuilt my library, it deleted that .obj file, whoopsy.....
I reincluded the project I needed, built my library, then rebuilt my project that was failing and it worked fine.
Moral of the story, verify your .obj file is where you are referencing it before diving too deep into the rabit hole.
I have had an issue with the same error within my project which I have managed to resolved.
The problem led me here but I found it to be a build file problem within visual studio itself.
If you cannot find anything wrong with your code and your doing all of the above I would recommend looking in the yourProject.vcxproj file and check that it is including your MyClass.cpp and source files as
SynthProject.vcxproj
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="myClass.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="myClass.h" />
</ItemGroup>
SynthProject.vcxproj.filters
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="myClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="myClass.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
and not as
SynthProject.vcxproj
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="myClass.h" />
<ClInclude Include="myClass.cpp" />
</ItemGroup>
SynthProject.vcxproj.filters
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="myClass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="myClass.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="myClass.cpp">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
I have managed to do this manually but would recommend unloading and adding the file back into the project if you do not have, or not using git.

Including c libraries in the custome code section of Simulink

I'm trying to include Csparse from SuiteSparse in to Simulink.
I've included the header ch.h and the directory of the c-functions in the custom code section.
If I call the function cs_compress over code.ceval I get this error:
cs_compress.obj : error LNK2019: unresolved external symbol cs_spalloc referenced in function cs_compress
Test2_sfun.mexw64 : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\link.exe"' : return code '0x460'
Stop.
The function cs_spalloc I presume is called from a library since there exists no cs_spalloc.c. The function is however defined in the header file as:
cs *cs_spalloc (csi m, csi n, csi nzmax, csi values, csi triplet) ;
Am I right to presume it is called from a library?
And if so where do I find the library in a format to include in to the custom code section in Simulink?
I found the c- functions cs_spalloc online, and just copyed it. Now it works.

Can't include iostream in C using MS Visual C++?

I've been trying to learn C, and I'm stuck on including libraries. I need to use strcpy(), but that method is included in the iostream library, but whenever I try to include the library, the program gives me errors. I've tried using "iostream", "iostream.h", , , but it either gives me a "can't find iostream.h" error, or the program exceeds 100 errors and just crashes. Even if my code is empty, I still get the same thing. Here's the code:
#include "iostream"
int main(void)
{
}
Yup, just that much makes it crash already. And here's a part of the errors I'm getting (could never paste them all here):
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2061: syntax error : identifier 'abs'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'acos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'asin'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan2'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'ceil'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): error C2061: syntax error : identifier 'cos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So yeah it even exceeds the 100 errors and the program just stops counting. I don't understand why, I'm just including a regular library. Is there an equivalent of strcpy()? I mainly wanted to use it like this (for practice):
#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "iostream"
int main(void)
{
struct person
{
int id;
char name[50];
int age;
};
struct person p1;
p1.id = 5595;
strcpy(p1.name, "Myname");
p1.age = 18;
printf("%d%s%d", p1.id, p1.name, p1.age);
}
<iostream> is a C++ header (it deals with input/ouput streams, as the name implies). If you want strcpy, you need <string.h>.
If your source file is ".c", all you have to do is to rename it ".cpp".
Then it'll compile as C++, you'll have the C++ headers, and you'll be able to use C++ streams.
I don't see any need for iostreams, however.
Strcpy and friends are in "<string.h>". Just include it, and "stdio.h" (like you're doing); delete the "iostreams" #include ... and life should be good.
iostreams are a C++-only feature. The iostreams header file is written in C++, not C. (Yes, they are different languages!) Presumably, you're invoking the compiler in C mode, so when the compiler looks at the header file it of course throws lots of errors since many of the constructs used in iostream makes sense only in C++ mode.
If you want to use iostreams, you have to compile in C++ mode (and code in proper, modern C++ accordingly), use a different library that's C-only or work around it by implementing your own code as necessary.
In this case, all you apparently want to do is to use strcpy(). That is declared in the string.h, not iostream. (string.h is a C header file.) Just #include <string.h> and it should compile.

structure repetition error compiling C WinSock code in visual studio 2010

I have been trying to compile C source code in visual studio 2010. While compiling i am getting some errors like:
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h(4277): error C2040: 'CONTEXT' : '_CONTEXT' differs in levels of indirection from 'binding *'
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winuser.h(5341): error C2365: 'INPUT' : redefinition; previous definition was 'enumerator'
1>c:\documents and settings\xyz\desktop\abc\clause.h(72) : see declaration of 'INPUT'
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h(176) : see declaration of 'timeval'
I searched for those error and but some hints that it is due to the change in order of the header files. But could not get the exact answer. May I know , How can I overcome this problem?
Following is the order of header file inclusions.
#include <WinSock2.h>
#include <Windows.h>
#include <stdio.h>
Thanks in advance.
See here - if you include windows.h explicitly with winsock2.h you have to add a #define WIN32_LEAN_AND_MEAN to make this work.
For historical reasons, the Windows.h
header defaults to including the
Winsock.h header file for Windows
Sockets 1.1. The declarations in the
Winsock.h header file will conflict
with the declarations in the
Winsock2.h header file required by
Windows Sockets 2.0. The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header.

Resources