Socket programming C++ error undefined reference -
Socket programming C++ error undefined reference -
this question has reply here:
visual c++ code not working in code::blocks 1 reply#pragma comment(lib,"ws2_32.lib") #include<sdkddkver.h> #include<conio.h> #include<stdio.h> #include<iostream> #include<winsock2.h> #include<windows.h> #define sck_version2 0x0202 using namespace std; int main() { long successful; wsadata winsockdata; word dllversion; dllversion=makeword(2,1); successful=wsastartup(dllversion,&winsockdata); sockaddr_in address; int addresssize=sizeof(address); socket sock_listen; socket sock_connection; sock_connection=socket(af_inet,sock_stream,null); address.sin_addr.s_addr=inet_addr("127.0.0.1"); address.sin_family=af_inet; address.sin_port=htons(444); sock_listen=socket(af_inet,sock_stream,null); bind(sock_listen,(sockaddr *)&address,sizeof(address)); listen(sock_listen,somaxconn); for(;;) { cout<<"\n\tserver:waiting incoming connection..."; if(sock_connection=accept(sock_listen,(sockaddr *)&address,&addresssize)); { cout<<"\n\ta connection found!"<<endl; successful=send(sock_connection,"welcome! connected server!",46,null); } } }
whenever seek building code server next errors:
i'm totally new. i'm using code blocks. i've been searching solution lastly 4 days i'm not understanding anything. please help
if using codeblocks, utilize mingw goes (i guess, according low experience level).
this feature works @ visual studio compilers:
#pragma comment(lib,"ws2_32.lib")
with mingw such #pragma not work.
instead if have open "project" -> "options", take project @ left tree (or "debug"/"release", if want alter work there), , open tab "link settings".
press "add" , find library name "libws2_32.a" in mingw/lib/ directory.
after seek rebuild. hope helps.
c++ sockets codeblocks
Comments
Post a Comment