C header files location

Simon simon80-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Sat Dec 9 04:13:09 UTC 2006


It's ok, man, we all went through this at some point.  During my first
week with Linux, I thought I needed a kernel recompile to get
ndiswrapper working for a couple hours.  Then I thought I needed to
compile the ndiswrapper module ( I had no clue what I was doing here,
either), and week later I think I realized that the kernel came with
the ndiswrapper module out of the box, and I could have just installed
the ndiswrapper-utils package to get it working.

Anyway, I don't know if you want the long explanation for this, but
here goes... VMWare is trying to compile a loadable kernel module to
extend the functionality of your kernel.  You may or may not know that
the Linux kernel is written in C, and you also may or may not know how
C compilation works.  I'm not suggesting that you don't, but in the
case that you don't, I'll explain that too.. C code can be split into
different files for larger projects, and in this case what will happen
is that all of the declarations of functions and user defined data
types (ie. how to call the functions or use the data types ) will go
into someheaderfile.h, and then the implementation  of the functions
will go into someheaderfile.c.  The .c file will have #include
"someheaderfile.h" at the start of the file, and at compile time, the
preprocessor just replaces the #include with the contents of
someheaderfile.h, and it's as if the code was all in one file.

Now, this opens up a bunch of possibilities: if you have something like
$ ls
useful_functions.h
useful_functions.c

and you write some more code in a separate file that calls a function
declared and defined in the above files, the compiler will complain
that you haven't declared the function you are trying to use.  To be
able to use the functions, though, you don't need to combine all the
code into one big file, you just need the header part, and that's why
they're separate.  The header just says how to call the functions you
want to use, and the .c file says what those functions do.  When you
want to use those functions, you #include the header, and then the
compiler will compile your code, including the function calls, without
actually having the functions that you're calling.  This produces a
yourcode.o file that has your code, but not the code in
useful_functions.c.  To make an executable out of your code, you need
a linker, which combines the code from functions.o and yourcode.o, and
adds some fluff to call the main function when your executable is run.

Now, this means that you only need useful_functions.o and
useful_functions.h to compile yourcode.c.  This makes it convenient to
package useful_functions.o into a shared library, and then your code
will just compile against useful_functions.h, and link against
libusefulfunctions.so.

I hope this all the way over your head, I realize my explanation has
gotten long and crappy..  The way this applies to your current
situation is that VMWare is compiling a kernel module which is going
to link with kernel code in order to add extra functionality to your
kernel.  You don't need the kernel source code (.c and .h files) to do
this, you just need the headers (only .h files) so that the compiler
will know how to call the functions that the module is going to use.
Installing the source will get you the headers, but it's overkill.
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list