linux CMake内部版本:未定义对libdrm的引用

ubby3x7f  于 2022-11-02  发布在  Linux
关注(0)|答案(1)|浏览(178)

我试着写一个drm的演示程序,但是我遇到了undefined reference to问题:

xjt@u16:~/SF6_RV1126/drmDemo/build$ make -j8
Scanning dependencies of target drmDemo
[ 50%] Building C object bin/CMakeFiles/drmDemo.dir/main.c.o
[100%] Linking C executable drmDemo
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: CMakeFiles/drmDemo.dir/main.c.o: in function `modeset_create_fb':
main.c:(.text+0x6c): undefined reference to `drmIoctl'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0xe0): undefined reference to `drmModeAddFB'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0x100): undefined reference to `drmIoctl'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: CMakeFiles/drmDemo.dir/main.c.o: in function `modeset_destroy_fb':
main.c:(.text+0x194): undefined reference to `drmModeRmFB'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0x1d4): undefined reference to `drmIoctl'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: CMakeFiles/drmDemo.dir/main.c.o: in function `main':
main.c:(.text+0x214): undefined reference to `drmModeGetResources'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0x248): undefined reference to `drmModeGetConnector'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0x2d4): undefined reference to `drmModeSetCrtc'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0x2f0): undefined reference to `drmModeFreeConnector'
/home/xjt/SF6_RV1126/RV1126/prebuilts/gcc/linux-x86/arm/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/8.3.0/../../../../arm-linux-gnueabihf/bin/ld: main.c:(.text+0x2f8): undefined reference to `drmModeFreeResources'
collect2: error: ld returned 1 exit status
bin/CMakeFiles/drmDemo.dir/build.make:94: recipe for target 'bin/drmDemo' failed
make[2]:***[bin/drmDemo] Error 1
CMakeFiles/Makefile2:85: recipe for target 'bin/CMakeFiles/drmDemo.dir/all' failed
make[1]:***[bin/CMakeFiles/drmDemo.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make:***[all] Error 2

我的cc工具链是从Buildroot生成的arm-linux-gnueabihf-。我使用CMake来构建我的程序。下面是我的项目树:

.
├── CMakeLists.txt        # 1
├── src
│   ├── main.c
│   └── CMakeLists.txt    # 2
└── build

在CML1中:

PROJECT(RV1126)

CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

SET(CMAKE_C_COMPILER "/home/xjt/SF6_RV1126/RV1126/buildroot/output/rockchip_rv1126_rv1109_dcir/host/bin/arm-linux-gnueabihf-gcc")

ADD_SUBDIRECTORY(src bin)

在CML2中:

SET(
    SRC_LIST
    main.c
)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR/bin})

ADD_EXECUTABLE(drmDemo ${SRC_LIST})

我想这是一个链接问题,我应该如何修改CMake链接到libdrm?

r1zhe5dt

r1zhe5dt1#

正如@Tsyvarev所说,在ADD_EXECUTABLE()之后加上LINK_LIBRARIES("....../lib/libdrm.so ")TARGET_LINK_LIBRARIES(demo libdrm.so)。再次感谢@Tsyvarev。

相关问题