LINUX.ORG.RU

Помогите скомпилить первый в жизни модуль.


0

0

Нахожусь в большом затруднении: Беру пример программы:

/* hello.c * * "Hello, world" - версия модуля ядра. */ #include < linux/kernel.h > /* Для выполнения работы в ядре */ #include < linux/module.h > /* Для создания модуля */ /* Точка входа - инициализация модуля */ int init_module(void) { printk("(1)Hello, world\n"); /* Если код возврата не нуль, то функция init_module завершилась неудачно и модуль ядра не будет загружен */ return 0; } /* Деинициализация модуля */ void cleanup_module(void) { printk("Goodbye, cruel world\n"); }

Делаю make файл:

# Makefile для модуля "Hello, world" CC = gcc CFLAGS := -Wall -DMODULE -D__KERNEL__ hello.o: hello.c $(CC) $(CFLAGS) -c hello.c echo insmod hello.o to install echo rmmod to delete

Запускаю:

make gcc -Wall -DMODULE -D__KERNEL__ -c -o hello.o hello.c hello.c:21:2: warning: no newline at end of file In file included from hello.c:7: /usr/include/linux/module.h:60: parse error before `atomic_t' /usr/include/linux/module.h:60: warning: no semicolon at end of struct or union /usr/include/linux/module.h:60: warning: no semicolon at end of struct or union /usr/include/linux/module.h:62: parse error before `}' /usr/include/linux/module.h:62: warning: data definition has no type or storage class /usr/include/linux/module.h:91: parse error before `}' hello.c: In function `init_module': hello.c:12: warning: implicit declaration of function `printk' make: *** [hello.o] Ошибка 1

Что мне бедному несчастному делать?


Пардон, постараюсь сделать удобочитабельнее:

Нахожусь в большом затруднении: Беру пример программы:

/* hello.c * * "Hello, world" - версия модуля ядра. */

#include < linux/kernel.h > /* Для выполнения работы в ядре */

#include < linux/module.h > /* Для создания модуля */

/* Точка входа - инициализация модуля */

int init_module(void) { printk("(1)Hello, world\n");

/* Если код возврата не нуль, то функция init_module завершилась неудачно и модуль ядра не будет загружен */

return 0;

} /* Деинициализация модуля */

void cleanup_module(void) {

printk("Goodbye, cruel world\n");

}

Делаю make файл:

# Makefile для модуля "Hello, world"

CC = gcc CFLAGS := -Wall -DMODULE -D__KERNEL__

hello.o: hello.c

$(CC) $(CFLAGS) -c hello.c

echo insmod hello.o to install

echo rmmod to delete

Запускаю:

make

gcc -Wall -DMODULE -D__KERNEL__ -c -o hello.o hello.c

hello.c:21:2: warning: no newline at end of file

In file included from hello.c:7:

/usr/include/linux/module.h:60: parse error before `atomic_t'

/usr/include/linux/module.h:60: warning: no semicolon at end of

struct or union

/usr/include/linux/module.h:60: warning: no semicolon at end of

struct or union

/usr/include/linux/module.h:62: parse error before `}'

/usr/include/linux/module.h:62: warning: data definition has no type

or storage class

/usr/include/linux/module.h:91: parse error before `}'

hello.c: In function `init_module':

hello.c:12: warning: implicit declaration of function `printk'

make: *** [hello.o] ошибка 1

Что мне бедному несчастному делать?

yuragv
() автор топика
Ответ на: комментарий от yuragv

Эх, девелоперы... :-)

С чего ты берешь инклуды ядра из /usr/include/linux ??? Они там НЕ ДЛЯ ЭТОГО. Сделай-ка ты сначала man gcc на предмет -I- и -I :-)

Хинт: -I/usr/src/linux/include :-)

no-dashi ★★★★★
()
Ответ на: комментарий от no-dashi

Классика утверждает, что если корректно установлены исходники текущего ядра, то при его сборке надо -I/lib/modules/`uname -r`/build/include (для 2.6 еще нужен путь к архитектурным заголовкам).

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