Solved

How to link socket.h?

Posted on 1997-02-25
6
360 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

626 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