C/C++/aaa

Unresolved External Error (WSAStartup, WSACleanup)

김컴맹 2012. 10. 16. 22:45
반응형

Hullo,

Beginning on my quest to learn Winsock, I've come across my first hitch. Sadly, it's pretty much my first line of code.

According to...I forget which tutorial it was now, but there was one out there (I think BJee) that said the only header I need to include is:
< winsock.h>

I'm beginning to believe this is not the case. I've created a Win32 Console Application in VC++ 6.0.

My code looks like:

Code:

 

#include <winsock.h>
void main(void)
{
const int WinsockVersion = 2;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(WinsockVersion, 0), &wsaData) == 0)
{
//Winsock goes in here
}
if (WSACleanup()!=0)
{
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <winsock.h>
void main(void)
{
const int WinsockVersion = 2;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(WinsockVersion, 0), &wsaData) == 0)
{
//Winsock goes in here
}
if (WSACleanup()!=0)
{
}
}

But, sadly, it does not run, giving me these errors:

Compiling...
Main.cpp
Linking...
Main.obj : error LNK2001: unresolved external symbol _WSACleanup@0
Main.obj : error LNK2001: unresolved external symbol _WSAStartup@8
Debug/Winsock.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...

No clue what I need to do. I'm thinking I may have missed some header? But no tutorials have told me which one.

 

---------------------------------------------------------------------------------------------------------------

 

Your code is fine, and its not an error with your code. You have all the headers you need. Your problem is a Linker error, which is what the compiler does after its finished compiling. While the headers have been included, the actual code that does the work is nowhere to be found, it has to be included in your project.

Winsock also comes with a library, wsock32.lib, which you link your project to with the line

#pragma comment(lib, "wsock32.lib")

Put that line under your #includes, and you should be ok

반응형

'C/C++ > aaa' 카테고리의 다른 글

C++ 컴파일러 지원  (0) 2015.10.19
ComboBox  (0) 2012.06.12
Afx Helper 함수(MFC)  (0) 2012.05.16
GetProcAddress  (0) 2012.05.16
ActiveX inf 파일  (0) 2012.04.12