Question:
Linker error: "undefined reference to..." I don't know how to fix :(?
2007-03-13 16:50:03 UTC
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
#include
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,IPPROTO_TCP);
sockin.sin_family=AF_INET;
sockin.sin_addr.s_addr = INADDR_ANY;
sockin.sin_port=htons(40254);
if(!bind(starts,(sockaddr *)&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.
Three answers:
Chris J
2007-03-13 16:55:41 UTC
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.
Walt Kolo
2007-03-13 20:40:44 UTC
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.
?
2016-11-25 06:29:48 UTC
spectacular now, extra effective() has no longer been defined. you have declared it, yet you have no longer written out the function physique. How is the pc meant to be attentive to what to do on that function call in case you have no longer presented a function physique? the pc can not examine your concepts, you ought to tell it what to do.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...