Solved

How to link socket.h?

Posted on 1997-02-25
6
359 Views
Last Modified: 2013-12-26
Hi! I'm a novice Unix user and is having problem in linking socket.h. During compiling, I get the following errors:

<-----------------------------Error msg begin-------------->
 "/usr/include/sys/socket.h", line 143: syntax error before or at: u_short
"/usr/include/sys/socket.h", line 143: cannot recover from previous errors
cc: acomp failed for host.c

<---------------------Error msg end ----------------------->
Thank you
0
Comment
Question by:chiang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Accepted Solution

by:
pc012197 earned 50 total points
ID: 1292293
What exactly is the problem? Is it compiling your code or does the error occur in the linking stage?

If the former is the case you should put the following line at the beginning of your code:

#include <socket.h>

If you get the error during linking you have to add the option

-lsocket

to the linking stage (in that case I suppose your working under Solaris...)

0
 

Author Comment

by:chiang
ID: 1292294
Edited text of question
0
 

Author Comment

by:chiang
ID: 1292295
Edited text of question
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:pc012197
ID: 1292296
What OS (type, version) are you using? What machine?

You may try to include <sys/types.h> before <sys/socket.h>.

0
 
LVL 2

Expert Comment

by:lockhart
ID: 1292297
You should _ALWAYS_ read the man page associated with any system call.  pc's suggestion to include sys/types.h before socket.h is born out by the man page on socket() which lists the include files needed for the call, and will give any special libraries needed as well.  If you do a "man socket" you'll see that you also need -lnsl in your link command.  It is a also good idea to use the include order and link order shown in the man page.

Mike
0
 
LVL 4

Expert Comment

by:jos010697
ID: 1292298
It has nothing to do with linking -- syntax errors are
all compiler complaints. My guess is (given the
syntax error on 'u_short') that chiang didn't include
<sys/types.h> in which the unsigned short is
defined as u_short ...

kind regards,

Jos
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 72
ORA-01403: no data found 43 116
FizzBuzz challenge 9 87
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,690
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question