gpt4 book ai didi

linux - 编译 Linux 内核 - Hello World

转载 作者:IT王子 更新时间:2023-10-29 00:59:14 26 4
gpt4 key购买 nike

我正在尝试编译 Linux 内核: http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

我有一个简单的 hello world 程序 hello-1.cpp

#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
return 0;
}

void cleanup_module(void)
{
}

但我正在尝试使用 Makefile 构建它:

obj-m += hello-1.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

我遇到了一些错误。

make -C /home/pacman/linux-2.6.34.11/2.6.35.6-45.fc14.i686/build M=/home/pacman/p1 modules
make: *** /home/pacman/linux-2.6.34.11/2.6.35.6-45.fc14.i686/build: No such file or directory. Stop.

make: * [所有] 错误 2

我是不是忘记定义什么了?

最佳答案

将 hello-1.cpp 重命名为 hello-1.c(模块必须用 C 语言编写)并添加以下行:

module_init(init_module);
module_exit(cleanup_module);

关于linux - 编译 Linux 内核 - Hello World ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253775/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com