ioport.h errors when compiling v4l2 program

806 views Asked by At

I wanted to follow this article about v4l2's driver writing.

But my first basic try failed when I include media/v4l2-dev.h (because I want to access some macro like VFL_TYPE_GRABBER).

media/v4l2-dev.h includes linux/device.h which includes linux/ioport.h which crashes with this output :

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’

[...]

The source :

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

#include <media/v4l2-dev.h>

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

I compiled with :

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

It occurs on 2.6.32-37-generic-pae with gcc 4.4.3 glibc 2.10 I tried the same on a gentoo with approximative equivalent version of kernel-headers and gcc.

What am I doing wrong ?

edit: indicate the exact includes path.

1

There are 1 answers

0
umläute On

if you are doing driver-development, you might as well use the provided frameworks to do so. i'd suggest to start with an existing build-project for a driver (e.g. that one), usually a Makefile as simple as this will do:

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

rather than trying to second-guess which include paths you need.

furthermore, you probably shouldn't include header-files before you need them.