LINUX.ORG.RU

trouble printk and printf


0

0

вот экзампл из Orelly http://www.xml.com/ldd/chapter/book/pdf/ch02.pdf

#define MODULE
#include <linux/module.h>

int init_module(void) {printk("<1>Hello, world\n";); return 0;}
void cleanup_module(void) {printk("<1>Goodbue cruel world\n";);}

и на команду gcc -c aa.cpp оно мне пишет:

[root@mobile100 robots]# gcc -c ee.cpp
ee.cpp: In function `int init_module()':
ee.cpp:4: `printk' undeclared (first use this function)
ee.cpp:4: (Each undeclared identifier is reported only once for each function
it appears in.)
ee.cpp:5:64: warning: no newline at end of file
[root@mobile100 robots]#

и как??

пробовал printf вместо printk
[root@mobile100 robots]# gcc -c ee.cpp
ee.cpp: In function `int init_module()':
ee.cpp:4: `printf' undeclared (first use this function)
ee.cpp:4: (Each undeclared identifier is reported only once for each function
it appears in.)
ee.cpp:5:64: warning: no newline at end of file

[root@mobile100 robots]# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-asplinux-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-asplinux-linux
Thread model: posix
gcc version 3.2.2 20030222 (ASPLinux 3.2.2-5asp)
[root@mobile100 robots]#
☆☆

[root@mobile100 robots]# uname -a
Linux mobile100 2.4.20-9asp #1 Wed Apr 30 01:13:27 MSD 2003 i686 athlon i386 GNU/Linux
[root@mobile100 robots]#

трабл какой-то короче...

vilfred ☆☆
() автор топика

Для printk нужен хеадер #include <linux/kernel.h> А на будущее читай manы printk (man printk)

Вот ссылка http://www.programme.ru/archive/2001/8/082001_1.phtml

Тут статья как писать драйвер. Хоть и очень начальный уровень, но от многих вопросов на начальном этапе избавит. Также поищи в нете Linux Kernel Module Guide он есть и на русском.

anonymous
()

З.Ы. при компиляции не забудь ключи -DMODULE -D__KERNEL__ -DLINUX

:)

anonymous
()

все равно фигня какая-то... 

[root@mobile100 robots]# cat ee.cpp
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void) {printk("<1>Hello, world\n"); return 0;}
void cleanup_module(void) {printk("<1>Goodbue cruel world\n");}
[root@mobile100 robots]# gcc -c -DMODULE -D__KERNEL__ -DLINUX ee.cpp
ee.cpp:1:1: warning: "MODULE" redefined
ee.cpp:1:1: warning: this is the location of the previous definition
In file included from /usr/include/linux/module.h:11,
                 from ee.cpp:2:
/usr/include/linux/list.h:37: parse error before `new'
/usr/include/linux/list.h: In function `void __list_add(...)':
/usr/include/linux/list.h:41: `next' undeclared (first use this function)
/usr/include/linux/list.h:41: (Each undeclared identifier is reported only once
   for each function it appears in.)
/usr/include/linux/list.h:41: parse error before `;' token
/usr/include/linux/list.h:44: `prev' undeclared (first use this function)
/usr/include/linux/list.h:44: parse error before `;' token
/usr/include/linux/list.h: At global scope:
/usr/include/linux/list.h:55: parse error before `new'
/usr/include/linux/list.h: In function `void list_add(...)':
/usr/include/linux/list.h:57: parse error before `,' token
/usr/include/linux/list.h: At global scope:
/usr/include/linux/list.h:68: parse error before `new'
/usr/include/linux/list.h: In function `void list_add_tail(...)':
/usr/include/linux/list.h:70: parse error before `,' token
ee.cpp: In function `int init_module()':
ee.cpp:5: `printk' undeclared (first use this function)


ладно, мож я ключи в неправильном порядке ставлю или еще че не шарю... пойду читать мануал. Спасибо!

vilfred ☆☆
() автор топика

понял, не ee.cpp, а ee.c :))

vilfred ☆☆
() автор топика

[root@mobile100 robots]# insmod ./ee.o
./ee.o: kernel-module version mismatch
./ee.o was compiled for kernel version 2.4.20
while this kernel is version 2.4.20-9asp.
[root@mobile100 robots]#

фсе, приехали...

vilfred ☆☆
() автор топика

а хидеры от ядра кто будет ложить или линковать в /usr/src? там, поди, от дефолтного дистрибутивного валяются? ну хотя бы собирай тогда с -I/usr/src/linux/include

SadStork
()

сорри - ложить и линковать в /usr/include :)

SadStork
()

Супер! Заработало!! спасибо за помощь чайнику!!

[root@mobile100 robots]# gcc -c -I/usr/src/linux-2.4.20-9asp/include ee.c
[root@mobile100 robots]# insmod ./ee.o
Warning: loading ./ee.o will taint the kernel: no license
See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module ee loaded, with warnings
[root@mobile100 robots]#

блин, а по приколу, это че еще за лицензия?? :))



vilfred ☆☆
() автор топика

а как посмотреть, какое прерывание свободно?

vilfred ☆☆
() автор топика

на одном прерывании (irq) может был несколько хендлеров (функций) капай в сторону free_irq или irq_free

MODULE_LICENSE("GPL")

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.