Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socket - call function

Status
Not open for further replies.

AnnaHere

IS-IT--Management
May 16, 2000
17
0
0
AU
Hello folks,<br>My problem is when I try and create a socket I get error undefined symbol socket.<br>I am sure the include files are correct.... (Unix platform)<br>What could be wrong ?<br><br><br><br><br>#include &lt;sys/types.h&gt;<br>#include &lt;sys/socket.h&gt;<br><br>main()<br>{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int s;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* get a socket */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s = socket(AF_UNIX, SOCK_STREAM, 0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;close(s);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(0);<br>}<br><br>Undefined&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;first referenced<br>&nbsp;symbol&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in file<br>socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/var/tmp/cc0MHiNS1.o<br>ld: fatal: Symbol referencing errors. No output written to a.out<br>
 
Hi Anna,<br><br>I hope you might have recoverd from this problem by now. Any way I feel that your<br>problem is related to PATH variable settings. I feel that the PATH specified on your<br>host m/c does not include correct search PATH for sys/socket.h and it may be different for differnet m/c like for HP - Unix it may differnt from DEC or SUN m/c.<br>So I advice you to find the exact PATH for your socket.h etc. If even it does not solve your problem I would certainly appreciate your feedback.<br><br>Regards,<br>Hecker
 
Hi Hecker ,<br>Am still trying to resolve, believe u are right its the path<br>Anna
 
i've encountered one thing using gcc even if the path is right and the right .h files are included you mau also need to put -lnsl and -lsocket in as some of the flags to your compiler
 
Yah Anna, Rotovegas is quite right . Actually even I have faced same problem sometimes. I just forgot to mention it so while using gcc or cc also mention -lnsl as an&nbsp;&nbsp;&nbsp;option on the command line.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top