Makefile include for unistd.h

Posted on 2008-10-29
Last Modified: 2013-12-26
I need to use sleep function and for that I have defined unistd. h.
How do i give include option for this file in makefile.
I tried externing the sleep function but it didn't worked.
  • 3
  • 2
  • 2
LVL 24

Expert Comment

ID: 22838704
You don't put that kind of stuff in a Makefile, you put it in the header or source file which needs unsitd.h, the only thing you put  in the Makefile are
e.g paths to the headers if they are in unusual places. Let us assume unistd.h is in /usr/local/include

then you coulc add this to your Makefile


In the C files you simply wrote:

#include <unitstd.h>

or in
#include <unistd.h>

You can not add anything like extra includes in  a Makefile


Author Comment

ID: 22839009
Thanks fridon,  actually my intent was to know include path only in Makefile as you have sggested, just that its a driver module Makefile. I have another problem now, the unistd.h is a user space file and I need the kernel space equivalent of it which I think is impelemented by the wait function. What is the include file for it.
Also what is the difference between CFLAGS and  EXTRA_CFLAGS

LVL 24

Expert Comment

ID: 22839465
Well it's up to you to give  it meaning. Howerver under gnu the  CFLAGS are handed automagically to the compiler I still prefer having it written out
like this

gcc $(CFLAGS)....

Now EXTRA_CFLAGS ist just a convenience. You may have some file which needs let's say /whatever/path/you/like
so you write before the rule

and use it thereafter

and later you may re-use the EXTRA_CFLAGS


or the like.

So I'd see CFLAGS as more general as EXTRA_CFLAGS but well in the end it's up to you to interpret it.

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

LVL 22

Expert Comment

ID: 22842496
You're writing a driver and you're calling sleep()?  That seems awfully fishy to me.  I haven't done any kernel programming, but I always thought that if you're in the kernel you have to be very careful about doing things that block.

When you're in the kernel, you don't have the full suite of user-mode utilities.  Many of those utilities depend on being able to block waiting for resources, but in the kernel you often do not have that luxury, especially in re-entrant code.

Author Comment

ID: 22848690
Thanks fridom,  I also read that CFLAGS is for top Makefile and EXTRA_CFLAGS otherwise.


Author Comment

ID: 22848702
NovaDenizen:  I subsequently decided to use sleep_on_interruptible.  kernel/sched.h.  It uses wait queue as a param and jiffies as another. Though there are too many variants, I think this shoud suffice.
LVL 22

Accepted Solution

NovaDenizen earned 100 total points
ID: 22851272
If that's available to you without jumping through any hoops, then it sounds better to me.  Just keep in mind that kernel development is a much more risky affair than user-level development.  If you do something sufficiently wrong you could do something destructive like hang your system, corrupt running executables, or make your disk unbootable.

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to show menu 5 88
sumNumber challenge 16 122
Path of Workbook 3 78
What is atomic operation? 6 59
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
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.

778 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