drm例子modeset-plane-test

4.16日更新:

其实这个问题是CSAPP里讲过的,编译命令里面,前面的项依赖后面的项。所以只要调整-ldrm选项的位置即可:gcc -I/usr/include/drm modeset-plane-test.c -o modeset-plane-test -ldrm

===============================

环境是ubuntu,尝试编译的示例代码来自于这里:

https://github.com/hexiaolong2008/sample-code/tree/master/drm/application/modeset-plane-test

但是编译不停出错:

$ gcc -I/usr/include/drm -ldrm modeset-plane-test.c -o modeset-plane-test
/usr/bin/ld: /tmp/ccog2T3L.o: in function `modeset_create_fb':
modeset-plane-test.c:(.text+0x7b): undefined reference to `drmIoctl'
/usr/bin/ld: modeset-plane-test.c:(.text+0xda): undefined reference to `drmModeAddFB'
/usr/bin/ld: modeset-plane-test.c:(.text+0xf7): undefined reference to `drmIoctl'
/usr/bin/ld: /tmp/ccog2T3L.o: in function `modeset_destroy_fb':
modeset-plane-test.c:(.text+0x19f): undefined reference to `drmModeRmFB'
/usr/bin/ld: modeset-plane-test.c:(.text+0x1d8): undefined reference to `drmIoctl'
/usr/bin/ld: /tmp/ccog2T3L.o: in function `main':
modeset-plane-test.c:(.text+0x234): undefined reference to `drmModeGetResources'
/usr/bin/ld: modeset-plane-test.c:(.text+0x266): undefined reference to `drmSetClientCap'
/usr/bin/ld: modeset-plane-test.c:(.text+0x270): undefined reference to `drmModeGetPlaneResources'
/usr/bin/ld: modeset-plane-test.c:(.text+0x290): undefined reference to `drmModeGetConnector'
/usr/bin/ld: modeset-plane-test.c:(.text+0x2ff): undefined reference to `drmModeSetCrtc'
/usr/bin/ld: modeset-plane-test.c:(.text+0x34e): undefined reference to `drmModeSetPlane'
/usr/bin/ld: modeset-plane-test.c:(.text+0x374): undefined reference to `drmModeFreeConnector'
/usr/bin/ld: modeset-plane-test.c:(.text+0x380): undefined reference to `drmModeFreePlaneResources'
/usr/bin/ld: modeset-plane-test.c:(.text+0x38c): undefined reference to `drmModeFreeResources'
collect2: error: ld returned 1 exit status

看上去好像一切都没有问题啊。后来查到这个网页:

https://github.com/vicamo/drm-utils/commit/c83303780f7d88079a0824c5c93a9d02ad270b0f

里面描述到:

make: specify build recipe for drm-info

Implicit rules fails to build on Ubuntu:

  drm-utils$ make
  cc -Wall `pkg-config --libs libdrm`  drm-info.o   -o drm-info
  /usr/bin/ld: drm-info.o: in function `getCapability':
  drm-info.c:(.text+0x30): undefined reference to `drmGetCap'
  ...

It seems Ubuntu GCC silently adds --as-needed to the linkage options
at a position before the input files and libraries, which then
effectively ignores -ldrm when expanded.

于是按这个思路修改编译命令:

gcc modeset-plane-test.c `pkg-config --cflags libdrm` `pkg-config --libs libdrm` -o modeset-plane-test

编译顺利通过。

但是运行还是有问题,会core dump。

代码例子来自这里:

https://blog.csdn.net/hexiaolong2009/article/details/84934294

运行到

crtc_id = res->crtcs[0];

这里时出错,可能res是空吧。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值