树莓派的官方V4L2驱动,如何在Makefile中添加lrt标志?

4 投票
2 回答
5943 浏览
提问于 2025-04-19 12:34

我正在创建一个小的Python应用程序,使用的是树莓派上的v4l。经过几个小时的排查,我快要安装成功了。现在只需要编译官方的V4L2驱动程序。

我在按照这个教程进行操作:https://www.ics.com/blog/raspberry-pi-camera-module#.VAaCHqM0_YQ

当我到达编译的步骤时,出现了这个错误:undefined reference to symbol 'clock_gettime'

我在谷歌上搜索了一下,发现需要“在链接的库列表中添加 -lrt”,或者把它放到makefile里。我对make和configure一点都不了解。我试着读了一点,但我这是为了工作,没时间去上课。我不知道该怎么办……请帮帮我……

我还应该提到,我不知道该修改makefile、makefile.in还是configure?我试着把"-lrt"放进makefile里,但这太复杂了,搞不清楚该放在哪里。

这是实际的错误信息:

Making all in v4l2-compliance
make[3]: Entering directory '/home/pi/v4l-utils/utils/v4l2-compliance'
  CXXLD  v4l2-compliance
/usr/bin/ld: v4l2-test-buffers.o: undefined reference to symbol 'clock_gettime@@
GLIBC_2.4'
//lib/arm-linux-gnueabihf/librt.so.1: error adding symbols: DSO missing from com
mand line
collect2: ld returned 1 exit status
Makefile:388: recipe for target 'v4l2-compliance' failed
make[3]: *** [v4l2-compliance] Error 1
make[3]: Leaving directory '/home/pi/v4l-utils/utils/v4l2-compliance'
Makefile:347: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/pi/v4l-utils/utils'
Makefile:386: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/pi/v4l-utils'
Makefile:315: recipe for target 'all' failed
make: *** [all] Error 2

我尝试编辑Makefile,发现有一行是“LIBS=”,我把它改成了“LIBS=-lrt”,但这并没有解决问题。

我在Makefile的第388行找到了这一段内容:

# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
#     (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
    @fail= failcom='exit 1'; \
    for f in x $$MAKEFLAGS; do \
      case $$f in \
        *=* | --[!k]*);; \
        *k*) failcom='fail=yes';; \
      esac; \
    done; \
    dot_seen=no; \
    target=`echo $@ | sed s/-recursive//`; \
    list='$(SUBDIRS)'; for subdir in $$list; do \
      echo "Making $$target in $$subdir"; \
      if test "$$subdir" = "."; then \
        dot_seen=yes; \
        local_target="$$target-am"; \
      else \
        local_target="$$target"; \
      fi; \
      ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
      || eval $$failcom; \
    done; \
    if test "$$dot_seen" = "no"; then \
      $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
    fi; test -z "$$fail"

所以我试着这样运行make:make CFLAGS='-lrt',但这也没有任何效果。我查看了config.status,这又是一个让我困惑的文件。

2 个回答

2

这个方法也可以用:

LDFLAGS=-lrt ./configure
make
2

我请了一个顾问,他告诉我需要修改两个不同的文件。

第一个文件:
/v4l-utils/utils/v4l2-compliance/Makefile

第二个文件:
/v4l-utils/utils/v4l2-ctl/Makefile

把里面有“LDFLAGS =”的那一行改成“LDFLAGS = -lrt”。

之后,V4l2在树莓派上编译得很好。

撰写回答