Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to link socket.h?

Posted on 1997-02-25
Medium Priority
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
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

Accepted Solution

pc012197 earned 100 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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