* Link lib to a kernel module
@ 2006-10-24 10:55 Matthias Fechner
2006-10-24 11:12 ` Dipti Ranjan Tarai
2006-10-24 12:11 ` Oleg Verych
0 siblings, 2 replies; 7+ messages in thread
From: Matthias Fechner @ 2006-10-24 10:55 UTC (permalink / raw)
To: linux-kernel
Hi,
I tried today to link a lib (.a) to my kernel module but I could not
found howto do it.
I prepared a little example:
hello.c:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/version.h>
#include "hello_lib.h"
MODULE_LICENSE("GPL");
int init_module(void)
{
printHello();
return 0;
}
void cleanup_module(void)
{
printk("remove module\n");
return;
}
hello_lib.c:
int helloWorld(void)
{
printk("Hello World\n");
return 0;
}
hello_lib.h:
int helloWorld(void);
Makefile:
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS+=-I/usr/home/idefix/programming/kernel_hello_world_lib/
obj-m := hello.o
hello-obj := hello.o libarinc653.a
all:
gcc -c -o hello_lib.o hello_lib.c
rm -f libhello_lib.a
ar cru libhello_lib.a hello_lib.o
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Can please someone help me here?
Thx a lot,
Matthias
--
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Link lib to a kernel module
2006-10-24 10:55 Link lib to a kernel module Matthias Fechner
@ 2006-10-24 11:12 ` Dipti Ranjan Tarai
2006-10-24 23:35 ` Matthias Fechner
2006-10-24 12:11 ` Oleg Verych
1 sibling, 1 reply; 7+ messages in thread
From: Dipti Ranjan Tarai @ 2006-10-24 11:12 UTC (permalink / raw)
To: kbuild-devel; +Cc: linux-kernel
Hi,
As per my knowledge kernel module can not access to a library
function. Library function are only accessible to user level program.
Module can access exported symbol only.
Regards
Dipti Ranjan Tarai
Matthias Fechner wrote:
> Hi,
>
> I tried today to link a lib (.a) to my kernel module but I could not
> found howto do it.
> I prepared a little example:
> hello.c:
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/io.h>
> #include <linux/version.h>
> #include "hello_lib.h"
>
> MODULE_LICENSE("GPL");
>
> int init_module(void)
> {
> printHello();
> return 0;
> }
>
> void cleanup_module(void)
> {
> printk("remove module\n");
> return;
> }
>
> hello_lib.c:
> int helloWorld(void)
> {
> printk("Hello World\n");
> return 0;
> }
>
> hello_lib.h:
> int helloWorld(void);
>
> Makefile:
> KDIR := /lib/modules/$(shell uname -r)/build
> PWD := $(shell pwd)
> EXTRA_CFLAGS+=-I/usr/home/idefix/programming/kernel_hello_world_lib/
>
> obj-m := hello.o
> hello-obj := hello.o libarinc653.a
>
> all:
> gcc -c -o hello_lib.o hello_lib.c
> rm -f libhello_lib.a
> ar cru libhello_lib.a hello_lib.o
> $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
>
> Can please someone help me here?
>
> Thx a lot,
> Matthias
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Link lib to a kernel module
2006-10-24 10:55 Link lib to a kernel module Matthias Fechner
2006-10-24 11:12 ` Dipti Ranjan Tarai
@ 2006-10-24 12:11 ` Oleg Verych
2006-10-25 12:26 ` [kbuild-devel] " Matthias Fechner
1 sibling, 1 reply; 7+ messages in thread
From: Oleg Verych @ 2006-10-24 12:11 UTC (permalink / raw)
To: linux-kernel; +Cc: kbuild-devel
Hallo, Matthias.
On 2006-10-24, Matthias Fechner wrote:
> I tried today to link a lib (.a) to my kernel module but I could not
> found howto do it.
`Documentation/kbuild' directory in your linux sources.
`makefiles.txt' about `lib-y',
`modules.txt' about modules.
Good luck.
____
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Link lib to a kernel module
2006-10-24 11:12 ` Dipti Ranjan Tarai
@ 2006-10-24 23:35 ` Matthias Fechner
[not found] ` <453EFA4C.9000502@innomedia.soft.net>
0 siblings, 1 reply; 7+ messages in thread
From: Matthias Fechner @ 2006-10-24 23:35 UTC (permalink / raw)
To: linux-kernel
Hi,
Dipti Ranjan Tarai schrieb:
> As per my knowledge kernel module can not access to a library
> function. Library function are only accessible to user level program.
> Module can access exported symbol only.
I don't want to build the module against a shared lib. I have here a lib
and I want that the lib is included into the kernel module.
I found in the documentation that it is possible to link the kernel
module with several object files (.o) and I found no source to do it
with libs (.a).
Thx
Matthias
--
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [kbuild-devel] Link lib to a kernel module
2006-10-24 12:11 ` Oleg Verych
@ 2006-10-25 12:26 ` Matthias Fechner
2006-10-25 18:24 ` Oleg Verych
0 siblings, 1 reply; 7+ messages in thread
From: Matthias Fechner @ 2006-10-25 12:26 UTC (permalink / raw)
To: kbuild-devel, linux-kernel
Hello Oleg,
* Oleg Verych <olecom@flower.upol.cz> [24-10-06 12:11]:
> `Documentation/kbuild' directory in your linux sources.
> `makefiles.txt' about `lib-y',
> `modules.txt' about modules.
I was now successfull with:
hello_lib.h:
int printHello(int);
hello_lib.c
int printHello(int count)
{
int i;
for(i=0;i<=count;i++)
{
printk("Hello World\n");
}
return 0;
}
hello.c:
#include <linux/kernel.h>
#include <linux/module.h>
#include "hello_lib.h"
MODULE_LICENSE("GPL");
int init_module(void)
{
printk("call function\n");
printHello(5);
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "remove module\n");
return;
}
Makefile:
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m += test.o
test-y := hello.o libhello_lib.a
all:
gcc -I/usr/include -c -o hello_lib.o hello_lib.c
rm -f libhello_lib.a
ar cru libhello_lib.a hello_lib.o
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules KBUILD_VERBOSE=1
Best regards,
Matthias
--
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Link lib to a kernel module
[not found] ` <453EFA4C.9000502@innomedia.soft.net>
@ 2006-10-25 12:30 ` Matthias Fechner
0 siblings, 0 replies; 7+ messages in thread
From: Matthias Fechner @ 2006-10-25 12:30 UTC (permalink / raw)
To: linux-kernel
Hello Dipti,
* Dipti Ranjan Tarai <dipti@innomedia.soft.net> [25-10-06 11:16]:
> Now in mod2 call test_export() of mod1, compile it and load the module u
> can able to access test_export().
thx for that hint, but I want one module :)
I was now successfull with the following code:
hello_lib.h:
int printHello(int);
hello_lib.c
int printHello(int count)
{
int i;
for(i=0;i<=count;i++)
{
printk("Hello World\n");
}
return 0;
}
hello.c:
#include <linux/kernel.h>
#include <linux/module.h>
#include "hello_lib.h"
MODULE_LICENSE("GPL");
int init_module(void)
{
printk("call function\n");
printHello(5);
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "remove module\n");
return;
}
Makefile:
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m += test.o
test-y := hello.o libhello_lib.a
all:
gcc -I/usr/include -c -o hello_lib.o hello_lib.c
rm -f libhello_lib.a
ar cru libhello_lib.a hello_lib.o
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules KBUILD_VERBOSE=1
Best regards,
Matthias
--
"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the universe trying to
produce bigger and better idiots. So far, the universe is winning." --
Rich Cook
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Link lib to a kernel module
2006-10-25 12:26 ` [kbuild-devel] " Matthias Fechner
@ 2006-10-25 18:24 ` Oleg Verych
0 siblings, 0 replies; 7+ messages in thread
From: Oleg Verych @ 2006-10-25 18:24 UTC (permalink / raw)
To: linux-kernel; +Cc: kbuild-devel
On 2006-10-25, Matthias Fechner wrote:
[]
> Makefile:
> KDIR := /lib/modules/$(shell uname -r)/build
> PWD := $(shell pwd)
there's $(CURDIR), just in case...
____
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-10-25 18:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-24 10:55 Link lib to a kernel module Matthias Fechner
2006-10-24 11:12 ` Dipti Ranjan Tarai
2006-10-24 23:35 ` Matthias Fechner
[not found] ` <453EFA4C.9000502@innomedia.soft.net>
2006-10-25 12:30 ` Matthias Fechner
2006-10-24 12:11 ` Oleg Verych
2006-10-25 12:26 ` [kbuild-devel] " Matthias Fechner
2006-10-25 18:24 ` Oleg Verych
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).