allkaiser

So, I'm working on a program that is using the WSA socket library. I've compiled it at my home computer using a command line C++ compiler (MinGW). However, when trying to compile it on a different computer using Visual Studio, I get all kinds of errors. For simplicity's sake, here's a shorter version of the code:

#include <Winsock2.h>
#include <Winsock.h>

#include <windows.h>
#include <stdio.h>

...
SOCKET socky;
WSADATA info;

if (WSAStartup(0x0202, &info)) {
printf("WSAStartup problem");
}

// create the socket
socky = socket(PF_INET, SOCK_STREAM, 0);
if(socky == INVALID_SOCKET){
printf("Socket call error");
exit(1);
...


And here are the errors:

socky.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function _main
socky.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _main
S:\graphics\socky\Debug\socky.exe : fatal error LNK1120: 2 unresolved externals

Visual studio is not finding any of the WSA functions. How do I fix this Am I missing a file Is it not finding a file What's going on!




Re: Visual C++ General Need help getting Windows sockets to work in Visual Studio C++

Christopher Prest

looks like you are not referencing the socket lib wsock32.lib

use:
#pragma commment(lib, "wsock32.lib")

edit: also add it to your library's properties.





Re: Visual C++ General Need help getting Windows sockets to work in Visual Studio C++

Vatroslav Mihalj

Or ws2_32.lib, which is the newer version




Re: Visual C++ General Need help getting Windows sockets to work in Visual Studio C++

allkaiser

Thanks! That fixed it (though you spelled comment wrong, which threw me off for a little bit)



Re: Visual C++ General Need help getting Windows sockets to work in Visual Studio C++

Christopher Prest

so it is :)

glade its working for you now.