This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: a little help beginning (kernel module)

On 05/02/2016 08:37 AM, Xen wrote:
> Hi.
> I have never really programmed in C or using makefiles before.
> Maybe I should say Makefiles ;-).
> It seems to me most Linux projects I have ever seen place object files 
> in the same directories as source files. To me that is rather ugly.

First observations are that your question isn't about C or the GCC 
compiler.  It is about a build environment and the tools which enable 
that.  In this case, *make* and *kbuild*.  I don't believe this forum is 
the right venue.  You'd probably find better support for things like on 
Stack Overflow.

> Also I am trying to compile a simple kernel module and unless I am 
> specifying explicitly this line form the tutorial:

Rather ambitious for, "... never really programmed in C or using 
makefiles before," don't you think?

> make -C /lib/modules/$(shell uname -r)/build  M=$(PWD) modules

Yes, without this, you have no hope of compiling your kernel module.  
Please read more on the kernel build system to understand why:

> Then it is impossible to compile anything because you run into a 
> million (header file inclusion) errors that seem completely unsolvable.

Yup  ...  read up on the kernel build environment.
> Apparently that build directory contains all the information (I 
> thought it would be an output directory).
> But now just one input file:
> module.c
> Produces in the same output directory 6 other files:
> module.ko
> module.mod.c
> module.mod.o
> module.o
> modules.order
> Module.symvers
> That would be okay if it was a dedicated output directory.
> So how can I put my source files in ./src, my output in ./build, and 
> so on?
> Make
> src/module.c
> dest/module.ko
> dest/module.mod.c
> dest/module.mod.o
> dest/module.o
> dest/modules.order
> dest/Module.symvers
> Or something of the kind?
> Any tutorials that might be helpful?

All of your questions should be answered by reading the link above and 
others related to kernel development.  Also, read up on "Linux Device 
Drivers"  That link is to the latest 
revision of the book which is, unfortunately, quite dated now.  However, 
the 4th edition is due out this year (I think), but nothing is yet 
available online.  Nevertheless, the link to LDD3 does cover, in 
sufficient depth, the kernel build environment.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]