Click to See Complete Forum and Search --> : About unresolved symbol printk
nickychen
04-16-2008, 12:05 AM
Hi
I try to make a module, and compile the module had not error msg. But when I insmod this module , I always got the msg : unresolved symbol XXX. the code and msg Like this:
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
int init_module(void)
{
printk("<1>hello \n");
return 0;
}
void cleanup_module(void)
{
printk("<1>bye \n");
}
The msg is : unresolved symbol printk
My Linux is Red Hat 9.0 kernel_ver : 2.4.20-8
why I always got this msg ???
Thx a lot......it let me beset some days......
bwkaz
04-16-2008, 09:43 PM
How did you compile the module?
nickychen
04-17-2008, 09:51 AM
Hi bwkaz
I used this compiling way...
>> gcc -D__KERNEL__ -D__SMP__ -DMODULE -DMODVERSIONS -I/usr/src/linux-2.4.20-8/include -Wall -O2 -o tst1.o -c tst1.c
and the module is named tst1
bwkaz
04-17-2008, 06:44 PM
It's been about 4 years since I used a 2.4 kernel, and I never did any development for them at all, so I don't know if that's right. I missed the part in your original post where you said this was on RH9, with that ancient kernel. Is there some reason you can't move to something that's newer than November 2002?
2.6 kernels have all the machinery in place to have the kernel itself build your module; that way you're sure that gcc was called with all the right options, from the right directory, etc., etc.
If not, I'm not going to be able to help very much, but I can look at a few issues that might possibly be causing this. First, do you have a /proc/kallsyms file? If so, is printk (on its own) listed in there? If you don't have that file, do you have the System.map file from the kernel build, and is printk in there?
Was your kernel built with module support? I'd think it was, but it's worth double checking. If you have any modules loaded at all, then it was built with module support, and this won't be the problem.
nickychen
04-18-2008, 03:32 AM
Hi bwkaz
Thx your suggest. I want to post Linux into PC104-plus and write pci device driver... And must let kernel be small (for RTlinux)...hmmm the 2.6 kernel too large... But I'll try update the 2.6 kernel again.
In the /proc/ksyms >> c011a260 printk
Besides I checked the kernel with " module support ". I'll still try to find some way to solve this problem....:)
bwkaz
04-18-2008, 07:14 PM
If you run nm on your module .o file, what does it print (especially regarding printk)? What if you run nm on a known-working module file? If there are any differences, they might be (part of) the cause.
(nm prints out each of the symbols that are defined or referenced in an object file. I believe it works on .o files, though I usually use it on full compiled binaries and .so files (shared libraries). Worth a shot anyway.)
nickychen
04-25-2008, 05:21 AM
Hi bwkaz
Sorry I don't know how to use nm But Last days I has solved the problem...
I found the <linux/kernel.h> has wrong, if I used gcc -D__KERNEL__ -D__SMP__ -DMODULE -DMODVERSIONS -I/usr/src/linux-2.4.20-8/include -Wall -O2 -o tst1.o -c tst1.c...
So I change the kernel source and use the Makefile (from the LINUX DEVICE DRIVERS, 2e, sample codes)....that's OK!!:) :)
I'm very thank you for help.
bwkaz
04-25-2008, 07:07 PM
Ah -- using sample code is always an option. That way you know someone else was able to get it to work, at least. :)
Great!