0

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.

roro
  • 131
  • 1
  • 2
  • 8
  • Sorry, this could sound _really_ patronising... but did you literally compile with `gcc -I/path/to/include -o prog prog.c` or did you specify the include path after the `-I`? – Harry Cutts May 22 '12 at 14:06
  • I didn't want to write the exact path in the quote, I will do it in the future to avoid this missunderstood. Actually, -I point to the includes of the kernel-headers. – roro May 22 '12 at 14:32
  • I'm pretty sure `asm/*.h` are not intended to be included directly by userspace programs. They're rather the kernel-header equivalent of `bits/*.h` for glibc headers, and get included indirectly by other headers (mainly `linux/*.h`). You should read up on the documentation for how to use this API rather than cargo-culting it... – R.. GitHub STOP HELPING ICE May 22 '12 at 15:00
  • I saw it could be usefull for linux/videodev2.h (don't have the link anymore). And by the way, it would be kernel side, not userspace. – roro May 22 '12 at 15:08
  • Which are you doing? Driver development or app development? You talk about driver development but then your code that's not working is userspace code (with `main` and all...). – R.. GitHub STOP HELPING ICE May 22 '12 at 15:10
  • hum, seems I didn't get something. Following the lwm article it is kernel side and not user-space side, it doesn't use the same V4l API. I thought I could test the use of the include with this way (my main and my gcc line). It seems not. How should I do ? – roro May 22 '12 at 15:19

1 Answers1

0

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.

umläute
  • 28,885
  • 9
  • 68
  • 122