Ich bin newbee zu Linux Kernel. Derzeit möchte ich 2 Module haben, die sie miteinander interagieren können. Ich habe versucht, Funktion2 von Modul2 in Modul1 von EXPORT_SYMBOL_GPL aufzurufen. Wenn ich modul1 "insmod", sagt es mir Funktion2 ist "unbekanntes Symbol" zu module1. Ich habe Funktion2 exportiert und -DEXPORT_SYMTAB in Makefile hinzugefügt. Was ich noch vermisse? Irgendwelche Ratschläge schätzen sehr."Unbekanntes Symbol" wird angezeigt, wenn "insmod" module1 die in module2 deklarierte Funktion aufruft
Hier ist meine hallo Proben
/* *************************************************************************************
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include "hello2.h"
static int __init init_module1(void)
{
printk(KERN_INFO "Hello world 1.\n");
function2();
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
static void __exit cleanup_module1(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
module_init(init_module1);
module_exit(cleanup_module1);
MODULE_DESCRIPTION("Hello1");
MODULE_LICENSE("GPL");
/* *************************************************************************************
* hello-2.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
static void function2 (void)
{
printk(KERN_INFO "Function called in hello2.\n");
}
EXPORT_SYMBOL_GPL(function2);
static int __init init_module2(void)
{
printk(KERN_INFO "Hello world 2.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
static void __exit cleanup_module2(void)
{
printk(KERN_INFO "Goodbye world 2.\n");
}
module_init(init_module2);
module_exit(cleanup_module2);
MODULE_DESCRIPTION("Hello2");
MODULE_LICENSE("GPL");
/* *************************************************************************************
* hello-2.h - The simplest kernel module header
*/
extern void function2 (void);
################################################
# Makefile for hello2
PWD := $(shell pwd)
KVERSION := $(shell uname -r)
KDIR := /lib/modules/$(shell uname -r)/build
KERNEL_DIR := /usr/src/linux-headers-$(KVERSION)/
INSTALL_PATH := /lib/modules/$(shell uname -r)/extra
EXTRA_CFLAGS = -DEXPORT_SYMTAB
MODULE_NAME = hello2
obj-m := hello2.o
#.PHONY: all clean insert
.PHONY: all clean
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
rm -rf *.o *.ko *.mod.* .c* .t*
insert:
$(MAKE) INSTALL_MOD_DIR=$(INSTALL_PATH) -C $(KDIR) M=$(PWD) modules_install
Vielen Dank für die Antwort auf meine Post. Ich habe versucht, 'function2' in nicht-statische zu ändern, aber ich bekomme immer noch "Unknown symbol function2" nach 'sudo insmod hello1.ko'. Es scheint, dass der Kernel 'function2' nicht finden kann, obwohl ich 'DEXPORT_SYMTAB' zum Kompilieren hinzufüge. Gibt es trotzdem ein 'hello2.ko' Symbol zum Kernel zu exportieren? –
Ich sehe, dass Sie einen anderen Grund für den Fehler entdeckt haben. Ich habe Ihren Beitrag hochgeladen - das ist sehr hilfreich. Es ist jedoch auch erforderlich, die Zielfunktion nicht statisch zu machen. Also, tatsächlich gab es * mehrere * Gründe, warum dein Modul fehlschlug, und die Funktion * static * zu verlassen war einer von ihnen. –
Vielen Dank für den Hinweis auf den nicht statischen Teil. Es ist großartig, dass Leute wie Sie Wissen beitragen, um Anfängern wie mir zu helfen! –