* build external module splited into several files
@ 2016-04-04 18:00 Colin Vidal
2016-04-04 18:47 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Colin Vidal @ 2016-04-04 18:00 UTC (permalink / raw)
To: kernelnewbies
Hi all,
I'm currently reading LDD the 3rd edition. Chapter 2 says that if we
need for example to build module "foo.c" which is split in two other
files "sub1.c" and "sub2.c", we just have to define the following
Kbuild variable in the makefile:
foo-objs := sub1.o sub2.o
I suppose that?
foo-y := sub1.o sub2.o
has the same semantic ? That's not very clear to me.
Anyway, the thing is that if I didn't use "sub1.c" and "sub2.c" (I
comment "foo-objs" line in the makefile and I define variables sub1 and
sub2 in "hello.c"), I've got the info messages in dmesg as well.
However, if I use "sub1.c" and "sub2.c" (the whole code at the end of
this mail), I get nothing, but the module still loaded anyway (insmod
returns no error and rmmod neither).
I think I'm missing something, but I didn't figure it out... I run
Linux 4.5 that I build from master sources. I'm not very settle into
the whole configuration options, so I use "make olddefconfig" on Fedora
4.4.6-300 config file.
Thanks,
Colin
---
Makefile:
obj-m := hello.o
hello-y := sub1.o sub2.o
KDIR=/lib/modules/$(shell uname -r)/build
all:
????????$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
????????$(MAKE) -C $(KDIR) M=$(PWD) clean
---
hello.c:
#include <linux/module.h>
#include <linux/printk.h>
extern int sub1;
extern int sub2;
static int __init hello_init(void)
{
????????pr_info("Hello, world! %d\n", sub1);
????????return 0;
}
static void __exit hello_exit(void)
{
????????pr_info("Bye. %d\n", sub2);
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
---
sub1.c:
int sub1 = 55;
---
sub2.c:
int sub2 = 345;
^ permalink raw reply [flat|nested] 3+ messages in thread* build external module splited into several files
2016-04-04 18:00 build external module splited into several files Colin Vidal
@ 2016-04-04 18:47 ` Greg KH
2016-04-04 19:43 ` Colin Vidal
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2016-04-04 18:47 UTC (permalink / raw)
To: kernelnewbies
On Mon, Apr 04, 2016 at 08:00:09PM +0200, Colin Vidal wrote:
> Hi all,
>
> I'm currently reading LDD the 3rd edition. Chapter 2 says that if we
> need for example to build module "foo.c" which is split in two other
> files "sub1.c" and "sub2.c", we just have to define the following
> Kbuild variable in the makefile:
>
> foo-objs := sub1.o sub2.o
>
> I suppose that?
>
> foo-y := sub1.o sub2.o
>
> has the same semantic ? That's not very clear to me.
Nope, not at all, stick with the "foo-objs" string instead please.
That should resolve your other issues here.
hope this helps,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* build external module splited into several files
2016-04-04 18:47 ` Greg KH
@ 2016-04-04 19:43 ` Colin Vidal
0 siblings, 0 replies; 3+ messages in thread
From: Colin Vidal @ 2016-04-04 19:43 UTC (permalink / raw)
To: kernelnewbies
On Mon, 2016-04-04 at 11:47 -0700, Greg KH wrote:
> On Mon, Apr 04, 2016 at 08:00:09PM +0200, Colin Vidal wrote:
> >?
> > Hi all,
> >?
> > I'm currently reading LDD the 3rd edition. Chapter 2 says that if
> > we
> > need for example to build module "foo.c" which is split in two
> > other
> > files "sub1.c" and "sub2.c", we just have to define the following
> > Kbuild variable in the makefile:
> >?
> > foo-objs := sub1.o sub2.o
> >?
> > I suppose that?
> >?
> > foo-y := sub1.o sub2.o
> >?
> > has the same semantic ? That's not very clear to me.
> Nope, not at all, stick with the "foo-objs" string instead please.
Hi Greg,
thanks for the clarification! However, I'm sorry but I'm still
confused: it's said in Documentation/kbuild/makefiles.txt on section
3.3, that if a module kernel is build from several sources file, we
have to use the module_name-y variable. Maybe a misunderstood the
context of this doc (the example is from in-tree kernel module) ?
> That should resolve your other issues here.
>?
> hope this helps,
Well, I tried again (with X-objs) but I've get the same issue :( No
hurry anyways, I have a scull driver to implements... :)
Thanks,
Colin
(PS: sorry for duplication)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-04 19:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-04 18:00 build external module splited into several files Colin Vidal
2016-04-04 18:47 ` Greg KH
2016-04-04 19:43 ` Colin Vidal
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).