1

I am trying to run the sample code from v4l2 API. When I tried to run the sample code, I am facing problem while compiling the program itself. Please check the error, is there something I need to install or flag to pass during the compilation steps?

ubox:~/capVideoFrame$ gcc v4l2grab.c && ./a.out
/tmp/cc0E2uRM.o: In function `xioctl':
v4l2grab.c:(.text+0x2b): undefined reference to `v4l2_ioctl'
/tmp/cc0E2uRM.o: In function `main':
v4l2grab.c:(.text+0xf3): undefined reference to `v4l2_open'
v4l2grab.c:(.text+0x30f): undefined reference to `v4l2_mmap'
v4l2grab.c:(.text+0x6a2): undefined reference to `v4l2_munmap'
v4l2grab.c:(.text+0x6c4): undefined reference to `v4l2_close'
collect2: error: ld returned 1 exit status

Source code header file:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include "/usr/include/libv4l2.h" // I am using ubuntu, so pointing to this location
fcdt
  • 2,371
  • 5
  • 14
  • 26
ajayramesh
  • 3,576
  • 8
  • 50
  • 75

2 Answers2

2

To successfully compiled you need add flags for it -lv4l1 -lv4l2

gcc v4l2grab.c -lv4l1 -lv4l2
Nick S
  • 1,299
  • 1
  • 11
  • 23
0

In case you didn't install libv4l2 before, you need to install it first:

sudo apt-get install -y libv4l-dev

BTW, the above link is dead, the new link is here.

  • Welcome to SO. I think the OP had already installed the library and the issue was not including the right flags. – ewokx Nov 02 '20 at 01:24