Solved

How to link socket.h?

Posted on 1997-02-25
6
341 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 57
My project did see openJDK that I installed. What could be the problem 7 123
Thin secure Windows 10 5 75
Capture logon name 13 31
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now