ubuntu - 如何修复错误 : implicit declaration of function ‘setup_timer’

标签 ubuntu makefile compilation linux-kernel include

正在尝试为 USB 声卡 Line6 UX2 编译 linux 核心模块。
从 repo 获取代码并尝试制作。 repo 没有 ./configure

使产生错误:

line6linux-code-r1108/driver/trunk/driver.c:169:2: error: implicit declaration of function ‘setup_timer’; did you mean ‘del_timer’? [-Werror=implicit-function-declaration]
  setup_timer(timer, function, data);
  ^~~~~~~~~~~
  del_timer

C 函数 setup_timer() 在 linux linux-headers 包中声明。目前是 linux-headers-4.18.0-16
当然它安装在默认位置/usr/src/

产生错误的代码(driver.c):

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/usb.h>

#include <sound/core.h>
#include <sound/initval.h>

#include "capture.h"
#include "driver.h"
#include "midi.h"
#include "playback.h"

... some code here

/*
    Setup and start timer.
*/
void line6_start_timer(struct timer_list *timer, unsigned long msecs,
               void (*function)(unsigned long), unsigned long data)
{
    setup_timer(timer, function, data); // <-- string 169
    mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
}
EXPORT_SYMBOL_GPL(line6_start_timer);

所以显然编译器找不到linux头文件。我该如何解决?

同样基于 INSTALL 文件,驱动程序是为内核版本 linux-headers-2.6.x 编写的,现在它是 4.18.0-16。

更多来自 INSTALL:对于其他发行版,请查阅文档以找出您必须安装的软件包。

一切都丢失了吗?

操作系统 Ubuntu 18.10
Linux 4.18.0-16-generic#17-Ubuntu SMP Fri Feb 8 00:06:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

最佳答案

在较新版本的 Linux 内核中,setup_timer函数被称为 timer_setup .

请注意,回调函数的类型在重新发布的版本中已更改。现在回调接受指向 timer_list 的指针结构本身。

在这篇 LWN 文章中查看更多信息:https://lwn.net/Articles/735887/ .

关于ubuntu - 如何修复错误 : implicit declaration of function ‘setup_timer’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55333646/

相关文章:

c++ - C++ 中的翻译单元与编译单元与目标文件与可执行文件与....

ubuntu - 我如何确定新启动的 VM 已准备好进行配置?

linux - 使用 env 变量指定 makefile

c++ - 如何将 sbatch 与 SLURM 和 makefile 一起使用?

makefile - 先决条件中的功能

c++ - ld : library not found for -lbitcoin

android - 启动失败 : Internal Error when starting Android Studio on ubuntu

java - 12.10 无法安装 eclipse

php - 发布生产代码的最佳方式

java gwt编译部署慢