当前位置: 首页 > 知识库问答 >
问题:

致命错误:linux/kthread.h:没有终止此类文件或目录编译

米浩穰
2023-03-14

我试图熟悉kthread,并编写了一个非常简单的程序来用C语言测试它,指导如下:http://tuxthink.blogspot.com/2011/02/kernel-thread-creation-1.html.我在MacOSX上的威睿运行Ubuntu。

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "cycle.h"
#include <linux/kthread.h>
#include <linux/sched.h>

int main(){
    static struct task_struct *kthread;

    thread1 = kthread_create(thread_fn, NULL, "thread1");
    wake_up_process(thread1);
    kthread_stop(thread1);

    return 0;
}

当我试图使用gcc (gcc test5.c -o test5.out)编译这个文件时,我得到“致命错误:linux/kthread.h:没有这样的文件或目录编译终止。”

我去/usr/include/linux/里面找的时候没有kthread.h文件,所以看起来很合理。当我搜索kthread.h时,我在/usr/src/Linux-headers-3 . 2 . 0-31/include/Linux中找到了一个,在/usr/src/Linux-headers-3 . 2 . 0-29/include/Linux中也找到了一个,但是在我尝试将其中一个复制到/usr/include/linux/中后,我总是得到错误消息:

In file included from /usr/include/linux/kthread.h:4:0,
             from test5.c:5:
/usr/include/linux/err.h:22:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’     before ‘ERR_PTR’
/usr/include/linux/err.h:27:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_ERR’
/usr/include/linux/err.h:32:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’     before ‘IS_ERR’
/usr/include/linux/err.h:37:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR_OR_NULL’
/usr/include/linux/err.h:49:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_CAST’
/usr/include/linux/err.h:55:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_RET’
In file included from test5.c:5:0:
/usr/include/linux/kthread.h:7:10: error: expected declaration specifiers or ‘...’ before numeric constant
/usr/include/linux/kthread.h:7:13: error: expected declaration specifiers or ‘...’ before numeric constant
/usr/include/linux/kthread.h:58:2: error: unknown type name ‘spinlock_t’
/usr/include/linux/kthread.h:59:19: error: field ‘work_list’ has incomplete type
/usr/include/linux/kthread.h:64:19: error: field ‘node’ has incomplete type
/usr/include/linux/kthread.h:66:2: error: unknown type name ‘wait_queue_head_t’
/usr/include/linux/kthread.h:67:2: error: unknown type name ‘atomic_t’
/usr/include/linux/kthread.h:128:1: error: unknown type name ‘bool’
test5.c: In function ‘main’:
test5.c:11:2: error: ‘thread1’ undeclared (first use in this function)
test5.c:11:2: note: each undeclared identifier is reported only once for each function it appears in
test5.c:11:12: error: ‘thread_fn’ undeclared (first use in this function)

任何关于如何解决这个问题的想法都将非常感谢!

共有1个答案

汤才捷
2023-03-14

这些是用于内核空间的内核线程,而不是用户空间线程!您应该使用适当的Makefile将代码更改为内核模块,或者将pthreads用于用户空间线程。也许您应该从HelloWorld内核模块开始

 类似资料:
  • 我正在尝试使用gcc执行tualth01.c,并且我将gcc和tudelaus01.c与libavcodec和libavformat及其相关文件放在同一文件夹中,它给了我这个错误 致命错误:libavcodec/avcodec. h没有终止此类文件或目录编译 当我通过Ubuntu12.04中的终端运行<code>gcc-o tutorial01 tutorial 01.c-lavformat-la

  • 问题内容: 我正在对GitHub上的此示例Angular2应用进行较小的修改,以使其使用Express.js而不是KOA。但是目前,当我尝试在FireFox中加载应用程序时,控制台中会显示以下错误: 当http请求触发路由器处理程序并返回时,Angular2应用程序开始加载,该处理程序返回,然后触发一系列嵌套依赖项的回调,其中一个引发错误并中途停止应用程序加载。 为了解决GitHub示例中的代码需

  • 问题内容: 我正在尝试使用C扩展文件构建共享库,但首先我必须使用以下命令生成输出文件: 执行命令后,我得到以下错误消息: :致命错误:Python.h:没有此类文件或目录编译终止。 实际上我已经尝试了所有建议的解决方案,但是问题仍然存在…我也没有问题。我设法在我的机器上找到该文件……以前有人遇到过同样的问题吗?? 问题答案: 看来你尚未正确安装python dev的标头文件和静态库。使用软件包管理

  • 我正在尝试使用C扩展文件构建一个共享库,但首先我必须使用下面的命令生成输出文件: 执行该命令后,我得到以下错误消息: 我已经尝试了所有建议的解决方案通过互联网,但问题仍然存在。我对没有任何问题。我设法在我的机器上找到了文件。

  • 我正在尝试安装mysqlclient,但我得到以下错误消息: _mysql.c:40:20:致命错误:python.h:没有终止此类文件或目录编译。错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为%1

  • 问题内容: 这些是/ usr / bin中的文件 我正在按照本教程交叉编译一个简单的C程序: 现在,我将其保存为.c文件,并尝试对其进行编译; 仅当我使用arm-linux-gnu-gcc时,这才令人发指。 但是当我使用gcc时,它工作正常。 为什么arm-linux *会出现此错误? 更新资料 详细 主机配置 Redhat 6,64位 问题答案: 看来,这里的问题是您为目标安装了编译器工具链,但