LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 12-08-2011, 01:09 AM   #1
Markus Franke
LQ Newbie
 
Registered: Nov 2010
Distribution: Ubuntu 11.04
Posts: 13

Rep: Reputation: 2
Accessing kernel headers from application?


Dear all,

in an embedded linux project I developed a simple character device driver which delivers some kernel space data up to a user space application. The data exchange is done with the help of an ioctl() command. The data type is specified as a "struct" and defined in a header file by itself within the kernel subtree. The IOCTL id's are defined within this file as well.

Now, if I would like to use my driver from an application I have to know this "struct" and the IOCTL id's and thus have to include kernel header files. But that means that in order to compile the application I would always have to include the kernel source, which is not really what I want. An alternative would be to simply copy the header file into the source code folder of the application but then I have a copy of the type definition and no one guarantees that both copys are identical.

What is the correct way of doing things like that? Any suggestions are highly appreciated.

Best regards,


Markus Franke
 
Old 12-13-2011, 02:17 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,854

Rep: Reputation: 161Reputation: 161
Why don't you want to include header file in kernel? A lot of header file will go into kernel eventually.
 
Old 12-13-2011, 03:10 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
nini09, I think you misunderstand the question (apologies to Markus Franke if I've got this wrong). I think the question is about how to include headers in application code, where the headers were originally created as part of kernel code. I, too, would like to understand the best-practice method to accomplish that. The objective being to insulate application code against the requirement to have kernel code present when building applications.
Often, there is a requirement to have kernel headers installed for the purpose of building other code. Perhaps this is the best-practice method. Also, kernel drivers are often accompanied by a library that wraps the driver access in a stable API, and that library's accompanying headers would provide the data structure definitions required for access to the device/driver. I would cite the open source Linux GPIB driver package as an example of this.

--- rod.
 
Old 12-14-2011, 01:17 AM   #4
Markus Franke
LQ Newbie
 
Registered: Nov 2010
Distribution: Ubuntu 11.04
Posts: 13

Original Poster
Rep: Reputation: 2
Dear theNbomr,

thanks for your reply. That's exactly what I was asking for. I am really wondering why there are so less answers on this thread because I think that there are supposed to be many people around who have already been faced with the same question.
Right now, I directly include the kernel headers from my application which unfortunately leads to the fact that I would always need the kernel sources (or at least the headers) for building it.

Any other suggestions?

Best regards,

Markus Franke
 
Old 12-23-2011, 08:21 PM   #5
jb_gpk
Member
 
Registered: Dec 2010
Distribution: Debian
Posts: 30

Rep: Reputation: 13
Hello!

Everybody that already wrote a driver with userspace interface knows this issue,
I do the following for my drivers:
* create the header on include/linux/my_driver_header.h
so, on my driver I include the header like this:
#include<linux/my_driver_header.h>
* After build the kernel I execute this rule:
Quote:
make headers_install make headers_install INSTALL_HDR_PATH=/usr/include
this rule exports the kernel headers to the /usr/include directory
the /usr/include is already a default header directory for the compiler, so, on my application I just include the header like this:
#include<linux/my_driver_header.h>

Last edited by jb_gpk; 12-23-2011 at 08:25 PM.
 
1 members found this post helpful.
Old 01-04-2012, 02:06 AM   #6
Markus Franke
LQ Newbie
 
Registered: Nov 2010
Distribution: Ubuntu 11.04
Posts: 13

Original Poster
Rep: Reputation: 2
Dear jb_gpk,

that was exactly the answer I was looking for. Btw...actually I should have RTFM. From linux kernel version 2.6.24 onwards there is a file <LINUX>/Documentation/make/headers_install.txt which explains exactly your solution. As I am on 2.6.22 I didn't find this file within my kernel sources.

I think this thread can be marked as "SOLVED" now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] accessing device driver from C application baraq Linux - Hardware 2 06-15-2011 02:47 AM
Zypper wants to dl the wrong kernel headers... YaST doesnt have current headers zorb SUSE / openSUSE 2 11-28-2009 11:12 AM
Accessing application information from within a socket LMAC Linux - Networking 0 04-23-2006 02:16 AM
finding out which application is accessing internet morphixrocks Linux - Networking 4 02-03-2006 03:13 AM
PHP: Accessing html headers harshnoise Programming 5 10-01-2005 09:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration