newbie question - winsock compile error

J

Jay

I am getting following error when trying to compile a sample program:

C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x38):test27.cpp:
undefined reference to `WSAStartup@8'
C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x71):test27.cpp:
undefined reference to `WSACleanup@0'

Here is my code:

// c program
#include <stdio.h>
#include <io.h>
#include <winsock.h>

int main()
{
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;

// Initialize WinSock.dll
nRet = WSAStartup(wVersionRequested, &wsaData);
if (nRet)
{
fprintf(stderr,"\nWSAStartup(): %d\n", nRet);
WSACleanup();
return 1;
}
return 0;
}

// END

How can I fix it?

Thanks in advance for any help.
 
M

Markus Cserna

Jay said:
I am getting following error when trying to compile a sample program:

C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x38):test27.cpp:
undefined reference to `WSAStartup@8'
C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x71):test27.cpp:
undefined reference to `WSACleanup@0'

Link ws2_32.lib into your program.

Regards,
Markus
 
B

bd

I am getting following error when trying to compile a sample program:

C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x38):test27.cpp:
undefined reference to `WSAStartup@8'
C:\DOCUME~1\user1\LOCALS~1\Temp\cckJbaaa.o(.text+0x71):test27.cpp:
undefined reference to `WSACleanup@0'

Winsock is not defined in the ISO C standard, and is thus off-topic in
comp.lang.c. Try comp.os.ms-windows.programmer.tools.winsock or some other
group with 'winsock' in the name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top