【问题标题】:ioport.h errors when compiling v4l2 program编译 v4l2 程序时出现 ioport.h 错误
【发布时间】:2012-05-29 00:58:04
【问题描述】:

我想关注这个article关于v4l2的驱动程序编写。

但是当我包含 media/v4l2-dev.h 时,我的第一次基本尝试失败了(因为我想访问像 VFL_TYPE_GRABBER 这样的宏)。

media/v4l2-dev.h 包括 linux/device.h,其中包括 linux/ioport.h,它会因此输出而崩溃:

In file included from /usr/src/linux/include/linux/device.h:16,
                 from /usr/src/linux/include/media/v4l2-dev.h:14,
                 from driv.c:11:
/usr/src/linux/include/linux/ioport.h:19: error: expected specifier-qualifier-list         before ‘resource_size_t’
/usr/src/linux/include/linux/ioport.h:116: error: expected declaration specifiers or ‘...’ before ‘resource_size_t’
/usr/src/linux/include/linux/ioport.h:116: error: expected declaration specifiers or ‘...’ before ‘resource_size_t’
/usr/src/linux/include/linux/ioport.h:121: error: expected declaration specifiers or ‘...’ before ‘resource_size_t’

[...]

来源:

#include <asm/types.h>
#include <linux/videodev2.h>

#include <media/v4l2-dev.h>

int main(int argc, char **argv) {
    return 0;
}

我编译的是:

gcc -I/usr/src/linux/arch/x86/include -I/usr/src/linux/include -o prog prog.c

它发生在 2.6.32-37-generic-pae 和 gcc 4.4.3 glibc 2.10 我在 gentoo 上尝试了同样的方法,它具有内核头文件和 gcc 的近似等效版本。

我做错了什么?

编辑:指明确切的包含路径。

【问题讨论】:

  • 抱歉,这听起来可能真的光顾...但是您是用gcc -I/path/to/include -o prog prog.c 编译还是在-I 之后指定了包含路径?
  • 我不想在引用中写出确切的路径,我以后会这样做以避免这种误解。实际上,-I 指向内核头文件的包含。
  • 我很确定asm/*.h 不打算直接包含在用户空间程序中。对于 glibc 头文件,它们相当于 bits/*.h 的内核头文件,并被其他头文件(主要是 linux/*.h)间接包含在内。您应该阅读有关如何使用此 API 的文档,而不是对它进行大肆宣传...
  • 我看到它可能对 linux/videodev2.h 有用(不再有链接)。顺便说一句,这将是内核端,而不是用户空间。
  • 你在做什么?驱动程序开发还是应用程序开发?您谈论驱动程序开发,但您的代码不起作用是用户空间代码(main 和所有......)。

标签: c header v4l2 v4l ioports


【解决方案1】:

如果您正在进行驱动程序开发,您不妨使用提供的框架来执行此操作。 我建议从现有的驱动程序构建项目开始(例如that 一个),通常是这样简单的 Makefile:

KERNEL_VERSION := `uname -r`
KERNEL_DIR := /lib/modules/$(KERNEL_VERSION)/build

PWD := $(shell pwd)

obj-m := mymodule.o

all: mymodule
mymodule:
    @echo "Building my driver..."
    $(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules
install:
    $(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules_install
    depmod -ae
clean:
    rm -f *~
    rm -f Module.symvers Module.markers modules.order
    $(MAKE) -C $(KERNEL_DIR) M=$(PWD) clean

而不是试图猜测你需要的路径。

此外,您可能不应该在需要头文件之前包含它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多