c - libusb 程序的 makefile

标签 c makefile linux-kernel libusb

我已经使用 libusb 制作了一个 C 程序,我正在使用以下命令来编译它:

gcc -o usbtest.o usbtest.c -lusb-1.0

程序运行良好。接下来,我将“usbtest.c”的代码添加到内核模块 (usbmod.c) 中,我被 make 文件困住了。我不确定我应该在“全部”部分传递什么命令。这是我所做的:

obj-m := usbmod.o

KERNEL_DIR = /lib/modules/$(shell uname -r)/build
PWD = $(shell pwd)

all:
    $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules

clean:
    rm -rf *.o *.ko *.mod.* *.symvers *.order *-

运行 make 后,出现以下错误:

anubhav@anubhav-Inspiron-3421:~/Desktop/usb$ make
make -C /lib/modules/3.13.0-46-generic/build     SUBDIRS=/home/anubhav/Desktop/usb modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
CC [M]  /home/anubhav/Desktop/usb/usbmod.o
/home/anubhav/Desktop/usb/usbmod.c:3:19: fatal error: stdio.h: No such  file or directory
#include <stdio.h>
               ^
compilation terminated.
make[2]: *** [/home/anubhav/Desktop/usb/usbmod.o] Error 1
make[1]: *** [_module_/home/anubhav/Desktop/usb] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
make: *** [all] Error 2

不确定是否需要将任何头文件带到我的工作目录或什么。请提供建议。

最佳答案

好的,所以这个链接在一定程度上澄清了我的疑惑:

[][1] error: stdio.h: No such file or directory error during make

它说“stdio.h”并且在内核空间中都不存在,因此会出现此类错误。此外,显然我的模块不包含任何 printf,所以我想我不需要“stdio.h”。

但它确实广泛使用了 libusb。那么,有没有办法真正创建这个模块。

关于c - libusb 程序的 makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29098739/

相关文章:

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

c - 变量数组声明

C代码将十六进制转换为整数

eclipse - 让 Eclipse CDT 在生成的 Makefile 中使用相对包含路径

c - 具有多个可执行文件的 Makefile

linux - 如何使用Linux软件看门狗?

c - 如何让 gcc ftrapv 工作?

c - 如何从源代码生成 .cpp 文件?

makefile - GNU make 中的错误 : target-specific variables are not expanded in implicit rules?

linux-kernel - 仅使用 CAP_BPF 无法在 BPF 程序中直接访问数据包?