LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-15-2012, 12:38 AM   #1
echipbk
LQ Newbie
 
Registered: Feb 2012
Posts: 13

Rep: Reputation: Disabled
Differences between library and modules


For library, we have static libraries and dynamic libraries
For module, many hardware drivers come in the form of driver modules

So, modules are used for kernel only as they can loaded or unloaded when necessary. Whereas libraries can be used for many other applications as well.

Is that correct? Or Are there anything needed to be added to that? Thank you.
 
Old 08-15-2012, 08:16 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Libraries are collections of object files; i.e., a function written in, say, C, that is compiled to an object file (a "dot.o") then inserted with other object files in a searchable file (called a library) where it or they may be extracted for use by a program at run time. Keep in mind that there are library files for other compiled languages (such as FORTRAN) which are used in the same way.

An example would be the basic hello_world program. In C, that would be
Code:
main ()
{
     printf ("Hello, world\n");
}
(that's as stripped down as it can get and not really the recommended way to code or good practice but it's just for example purposes).

The printf() function is one of the object files in a library file named libc; libc will be libc.so (dynamic) or libc.a (static). Same source code, different library file structure. Too, printf() does not stand alone, it calls a number of other functions (in libc) to actually put Hello, world on a terminal window. See the man page for the ld program for more detail about how this is done.

Modules are also functions (in the C sense) that dynamically are loaded or unloaded by the kernel as needed. The kernel can be built statically where only the drivers for a particular hardware set are compiled in (rather than compiled as modules).

So, yes, you've got it pretty much right; wouldn't hurt to browse though the manual pages, including the SEE ALSO section at the bottom of manual pages for related information. The gcc manual page might be a good place to start.

How should helo_world.c really look (so the compiler doesn't yammer at you)?
Code:
#include <stdio.h>

int	main (void)
{
	printf ("Hello, world\n");
}
Not much more there, but it's cleaner.

Hope this helps some.
 
1 members found this post helpful.
Old 08-15-2012, 09:06 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You are correct, but a kernel module is a special library. It is constructed in a certain way and runs in the kernel environment. When a C program runs, there is a C run time environment. The kernel has it's own environment, and can only run kernel libraries. The included files are different as well.

A C program uses system calls when it needs the kernel to perform a function. Either directly, or via a standard C function. The kernel is on the other side of the fence, and it is what executes these system calls that userland programs are calling.
 
1 members found this post helpful.
Old 08-15-2012, 09:08 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
The concepts of "static and dynamic libraries" are purely a userland concept, having to do (only!) with the application programs that run in user space.

"Kernel modules" are special, privileged modules which can be loaded on-demand by the kernel and which become, once loaded, "fully part of" the kernel until (and unless) the modules are unloaded again.

While the concepts are similar (and the kernel module-loader in fact understands how to read and to process the binary file formats that are also used in userland ...) the purposes are entirely different.
 
1 members found this post helpful.
  


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
[SOLVED] Differences between ncurses library and termios struct w.r.t Keyboard reading Aquarius_Girl Programming 8 11-22-2014 01:44 PM
Why can't the system import modules from the Python Standard Library in Ubuntu? c00kiemonster Linux - General 1 01-23-2011 12:23 AM
rootkit hunter warning found differences in output kernel modules opto Linux - Security 6 02-06-2007 07:30 PM
Kernel Recompile missing library modules Bear Linux - Software 4 03-26-2002 05:28 PM
Re: modprobe: Note: /etc/modules.conf is more recent than lib/modules/2.4.9/modules.d Andy.M Linux - Newbie 2 01-24-2002 01:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

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