Monday, July 27, 2009

Linker error: "undefined reference to..." I don't know how to fix :(?

I am using dev c++ and getting a linker error. I understand what it means somewhat, but I do not know how to fix it. Here is my program:





#include %26lt;stdio.h%26gt;


#include %26lt;winsock2.h%26gt;


int main(int argc, char *argv[])


{ int starts, s; sockaddr_in sockin; WSAData *wsa;


if(WSAStartup(MAKEWORD(1,1),wsa))


return 1;


starts=socket(AF_INET,SOCK_STREAM,IPPROT...


sockin.sin_family=AF_INET;


sockin.sin_addr.s_addr = INADDR_ANY;


sockin.sin_port=htons(40254);


if(!bind(starts,(sockaddr *)%26amp;sockin,sizeof(struct sockaddr_in)))


return 2;


scanf("");


WSACleanup();


return 0;


}





i get undefined reference to: 'WSAStartup@8', socket@12, htons@4, bind@12, WSACleanup@0





I do not really understand how to link a .dll. Thanks for your help.

Linker error: "undefined reference to..." I don't know how to fix :(?
Link to wsock32.lib (regular windows) or ws2_32.lib (windows NT) using the Input\Additional Dependencies field on the Linker tab/folder of the project Properties.
Reply:I'm glad I could be, at least, a little bit helpful. Happy programming! Report It

Reply:I'm not familar with the above code, though the error seems to imply you're missing a linking library.





In Dev++, create a new project, delete main.cpp file created. From that point, right click on project, select add to project (you would add your own cpp file).





Linking. Right click on project, select project options. At that point it's a matter of using the built add object or library button to locate your missing linker file. Once found, click ok.


No comments:

Post a Comment