How to link socket.h?

Posted on 1997-02-25
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
Question by:chiang

Accepted Solution

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


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


Author Comment

ID: 1292294
Edited text of question

Author Comment

ID: 1292295
Edited text of question
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Expert Comment

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

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


Expert Comment

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.


Expert Comment

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,


Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 180
bigDiff challenge 17 126
Fibonacci challenge 11 133
Problem to App source 6 75
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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