Ubuntu18交叉编译AArch64时GStreamer -l链接错误求助
Ubuntu 18下GStreamer AArch64交叉编译链接错误问题
错误信息
编译时出现如下链接错误:
/usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so when searching for -lgstreamer-1.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: cannot find -lgstreamer-1.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libgobject-2.0.so when searching for -lgobject-2.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libgobject-2.0.a when searching for -lgobject-2.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: cannot find -lgobject-2.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libglib-2.0.so when searching for -lglib-2.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libglib-2.0.a when searching for -lglib-2.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: cannot find -lglib-2.0 /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.a when searching for -lm /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
已尝试操作与环境信息
- 系统:Ubuntu 18
- GStreamer版本:1.14.5
- 已安装
pkg-config-aarch64,参考社区相关讨论后仍未解决问题 - 检查发现AArch64架构对应的目录下无GStreamer的
.pc文件,推测需安装AArch64版本的GStreamer,但不清楚Ubuntu下的操作步骤 - 仅在使用pkg-config进行AArch64交叉编译时出现该问题
相关配置片段
CMake配置片段
find_package(PkgConfig REQUIRED) pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) # Include directories include_directories( ${GLIB_INCLUDE_DIRS} ${GSTREAMER_INCLUDE_DIRS} ) #linking GStreamer library directory link_directories( ${GLIB_LIBRARY_DIRS} ${GSTREAMER_LIBRARY_DIRS} ) add_executable(yo_gst tutorial_2.cpp) target_include_directories(yo_gst PUBLIC ${GSTREAMER_INCLUDE_DIRS}) target_link_libraries(yo_gst PUBLIC ${GSTREAMER_LIBRARIES})
交叉编译脚本片段
export PKG_CONFIG_ALLOW_CROSS=1 export PKG_CONFIG_PATH=/usr/bin/pkg-config:$PKG_CONFIG_PATH
pkg-config查询结果
pkg-config --list-all |grep gstreamer gstreamer-video-1.0 GStreamer Video Library - Video base classes and helper functions gstreamer-riff-1.0 GStreamer RIFF Library - RIFF helper functions gstreamer-1.0 GStreamer - Streaming media framework gstreamer-net-1.0 GStreamer networking library - Network-enabled GStreamer plug-ins and clocking gstreamer-pbutils-1.0 GStreamer Base Utils Library - General utility functions gstreamer-app-1.0 GStreamer Application Library - Helper functions and base classes for application integration gstreamer-audio-1.0 GStreamer Audio library - Audio helper functions and base classes gstreamer-tag-1.0 GStreamer Tag Library - Tag base classes and helper functions gstreamer-plugins-base-1.0 GStreamer Base Plugins Libraries - Streaming media framework, base plugins libraries gstreamer-allocators-1.0 GStreamer Allocators Library - Allocators implementation gstreamer-rtsp-1.0 GStreamer RTSP Library - RTSP base classes and helper functions gstreamer-check-1.0 GStreamer check unit testing - Unit testing helper library for GStreamer modules gstreamer-base-1.0 GStreamer base classes - Base classes for GStreamer elements gstreamer-fft-1.0 GStreamer FFT Library - FFT implementation gstreamer-sdp-1.0 GStreamer SDP Library - SDP helper functions gstreamer-rtp-1.0 GStreamer RTP Library - RTP base classes and helper functions gstreamer-controller-1.0 GStreamer controller - Dynamic parameter control for GStreamer elements gstreamer-gl-1.0 GStreamer OpenGL Plugins Libraries - Streaming media framework, OpenGL plugins libraries
解决方案
1. 安装AArch64架构的GStreamer依赖包
Ubuntu支持多架构包管理,先开启AArch64架构支持:
sudo dpkg --add-architecture arm64 sudo apt update
然后安装AArch64版本的核心依赖:
sudo apt install libgstreamer1.0-dev:arm64 libgstreamer-plugins-base1.0-dev:arm64 libglib2.0-dev:arm64
2. 修正pkg-config交叉编译环境配置
原脚本的PKG_CONFIG_PATH配置错误,需指定AArch64架构的.pc文件路径,并使用对应架构的pkg-config工具。修改交叉编译脚本:
export PKG_CONFIG_ALLOW_CROSS=1 # 指定AArch64专属的pkg-config工具 export PKG_CONFIG=/usr/bin/aarch64-linux-gnu-pkg-config # 优先查找arm64架构的库配置文件路径 export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH
3. 配置CMake交叉编译工具链
创建toolchain-aarch64.cmake文件,指定交叉编译相关参数:
set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) # 指定交叉编译器 set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc) set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++) # 指定AArch64架构的pkg-config工具 set(PKG_CONFIG_EXECUTABLE /usr/bin/aarch64-linux-gnu-pkg-config) set(PKG_CONFIG_ALLOW_CROSS ON) # 设置系统根目录(使用Ubuntu自带的交叉编译根文件系统) set(CMAKE_SYSROOT /usr/aarch64-linux-gnu) # 确保CMake只在目标架构路径中查找库和头文件 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
编译时指定工具链文件:
cmake -S . -B build-aarch64 -DCMAKE_TOOLCHAIN_FILE=toolchain-aarch64.cmake cmake --build build-aarch64
4. 验证配置有效性
执行以下命令确认pkg-config能正确识别AArch64架构的GStreamer库:
aarch64-linux-gnu-pkg-config --cflags gstreamer-1.0 aarch64-linux-gnu-pkg-config --libs gstreamer-1.0
若输出正常的编译、链接参数,说明配置正确。
内容的提问来源于stack exchange,提问作者Abdul Rehman
相关产品推荐
相关产品推荐

