LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2008, 01:40 AM   #1
shilu72000
LQ Newbie
 
Registered: May 2008
Posts: 2

Rep: Reputation: 0
Compiling Linux kernel using Cross Compiler


Hi,

I am working on Linux kernel 2.6. I have created a simple kernel module.I have compiled it by preparing a sample makefile for the same. I could see that module compiles successfully and creates a .ko file for the same when i give make command on the terminal.I have also installed the module and i have dmesg' it to see the output on the terminal and it works.

Now I have ARM GNU cross compiler and I would like to compile the same kernel module using that cross compiler.The problem starts now when i start compiling it.

The options to be used for cross compiling any simple .c file would be tjis way:
arm-none-linux-gnueabi-gcc -static hello_proc.c -o hello

Now I am using the same option for cross compiling the kernel module.But after compiling I obtain lot of errors which look this way:

arm-none-linux-gnueabi-gcc -static -c -o hello_proc.o hello_proc.c
hello_proc.c:9:17: error: init.h: No such file or directory
hello_proc.c:10:26: error: linux/module.h: No such file or directory
hello_proc.c:11:27: error: linux/proc_fs.h: No such file or directory
hello_proc.c:17: error: expected declaration specifiers or '...' before 'off_t'
hello_proc.c: In function 'hello_read_proc':
hello_proc.c:20: warning: incompatible implicit declaration of built-in function 'strlen'
hello_proc.c:25: error: 'EINVAL' undeclared (first use in this function)
hello_proc.c:25: error: (Each undeclared identifier is reported only once
hello_proc.c:25: error: for each function it appears in.)
hello_proc.c:30: error: 'offset' undeclared (first use in this function)
hello_proc.c:35: warning: incompatible implicit declaration of built-in function 'strcpy'
hello_proc.c: At top level:
hello_proc.c:45: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello_init'
hello_proc.c:61: warning: data definition has no type or storage class
hello_proc.c:61: warning: parameter names (without types) in function declaration
hello_proc.c:63: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hello_exit'
hello_proc.c:68: warning: data definition has no type or storage class
hello_proc.c:68: warning: parameter names (without types) in function declaration
make: *** [hello_proc.o] Error 1

hence I request you to tell me if the way i am compiling a kernel module using a cross compiler is right or wrong?

My kernel module looks like this:

/*
* "Hello, world!" minimal kernel module - /proc version
*
* Valerie Henson <val@nmt.edu>
*
*/

//#include <linux/init.h>
#include<init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>

/*
* Write "Hello, world!" to the buffer passed through the /proc file.
*/

static int hello_read_proc(char *buffer, char **start, off_t offset, int size, int *eof,void *data)
{
char *hello_str = "Hello, world!\n";
int len = strlen(hello_str); /* Don't include the null byte. */
/*
* We only support reading the whole string at once.
if (size < len)
return -EINVAL;
/*
* If file position is non-zero, then assume the string has
* been read and indicate there is no more data to be read.
*/
if (offset != 0)
return 0;
/*
* We know the buffer is big enough to hold the string.
*/
strcpy(buffer, hello_str);
/*
* Signal EOF.
*/
*eof = 1;

return len;

}

static int __init hello_init(void)
{
/*
* Create an entry in /proc named "hello_world" that calls
* hello_read_proc() when the file is read.
*/
if (create_proc_read_entry("hello_world", 0, NULL, hello_read_proc,
NULL) == 0) {
printk(KERN_ERR
"Unable to register \"Hello, world!\" proc file\n");
return -ENOMEM;
}

return 0;
}

module_init(hello_init);

static void __exit hello_exit(void)
{
remove_proc_entry("hello_world", NULL);
}

module_exit(hello_exit);
 
Old 05-26-2008, 04:59 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
Clearly, it doesn't find init.h.
Maybe you should cross-compile the libs and the kernel..
http://trac.cross-lfs.org/wiki/WikiStart
 
Old 05-26-2008, 05:29 AM   #3
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
When you compile the program for platform you are running on, you use the make file in which you define the library location, but while cross compiling also you need to specify library location.

It is just like you are compiling for your on platform and giving command

gcc proc.c -o proc
 
Old 05-26-2008, 07:53 AM   #4
shilu72000
LQ Newbie
 
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
pls explain in detail

Can you pls tell me in detail to how u have to cross compile the libs and the kernel


Quote:
Originally Posted by Agrouf View Post
Clearly, it doesn't find init.h.
Maybe you should cross-compile the libs and the kernel..
http://trac.cross-lfs.org/wiki/WikiStart
 
Old 05-26-2008, 12:45 PM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
If you have to link with libs, I believe they should be compiled for arm, no?
Anyway for the include files, I believe you have to indicate their location with -I
 
  


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
Trouble building a Cross Compiler to use to build a x86_64 kernel. nLEyETn Linux - Software 2 05-08-2007 06:35 PM
windows to linux cross-compiler back2morrie Linux - General 8 07-13-2005 03:15 AM
Kernel compilation error using cross compiler bond_7942 Linux - Software 0 02-02-2005 12:18 AM
GNU libc installation to setup cross compiler env - kernel header file TOO OLD !! tanch00 Linux - Software 1 02-06-2002 02:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:30 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