ubuntu20.04编译librealsense

1.直接安装

直接接用sudo apt的方便,安装成功后发现没有intel的相机,ls usb查看接入虚拟机设备,如果没有的话,将设置里面的usb改为兼容3.1

参考 Ubuntu20.04LTS下安装Intel Realsense D435i驱动与ROS包_wanghq2013的博客-CSDN博客_d435i ros

2.用源码安装

源代码安装:
git clone librealsense的源代码

GitHub - IntelRealSense/librealsense: Intel® RealSense™ SDK

太卡的话可以用gitee 登录 - Gitee.com
进入该目录
安装依赖
sudo apt-get install libudev-dev pkg-config libgtk-3-dev
sudo apt-get install libusb-1.0-0-dev pkg-config
sudo apt-get install libglfw3-dev
sudo apt-get install libssl-dev

sudo apt-get install mesa-common-dev
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev

sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger 
mkdir build
cd build
cmake ../ -DBUILD_EXAMPLES=true
cmake时会报错
 Policy CMP0072 is not set: FindOpenGL prefers GLVND by default when   available.  Run "cmake --help-policy CMP0072" for policy details.  U
make
解决方法:
在cameklists中添加一行
cmake_policy(SET CMP0072 NEW)
将set(BUILD_WITH_TM2 OFF) 修改为 set(BUILD_WITH_TM2 ON)
屏蔽网络校验
sudo gedit librealsense/CMake/connectivity_check.cmake
将INTERNET_CONNECTION 后面的OFF修改为ON,即:
set(INTERNET_CONNECTION ON)

然后重新cmake
再make
sudo make install

3.脚本编译 

脚本如下:

前提安装依赖:

sudo apt-get install -y libudev-dev pkg-config libgtk-3-dev libusb-1.0.0-dev libglfw3-dev libssl-dev  mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev

#! /bin/bash
set -x
PACKAGE=librealsense
if [ "$LIBREALSENSE_VERSION" == "" ]; then
    VERSION=2.43.0
else
    VERSION=$LIBREALSENSE_VERSION
fi
URL=https://gitee.com/guchaono1/librealsense/repository/archive/master.zip
FILENAME=$PACKAGE-$VERSION
BUILD_ROOT=`pwd`/build/$ST_TARGET_TUPLE
DOWNLOAD_PATH=`pwd`/build/download/$FILENAME
SRC_PATH=`pwd`/build/src/$PACKAGE-$VERSION
OBJ_PATH=$BUILD_ROOT/obj/$PACKAGE-$VERSION
INSTALL_PATH=$BUILD_ROOT/output
CONAN_PATH=$BUILD_ROOT/conan_$PACKAGE

if [ "$ST_TARGET_ARCH" == "x86_64" ]; then
    CFLAGS="-m64"
elif [ "$ST_TARGET_ARCH" == "i386" ]; then
    CFLAGS="-m32"
else
    CFLAGS=""
fi

if [ "$ST_HOST" == "" ]; then
    CONFIG_FLAGS=""
else
    CONFIG_FLAGS="--host=$ST_HOST"
fi
 

function download()
{
    mkdir -p $(dirname $DOWNLOAD_PATH)
    if [ ! -f "$DOWNLOAD_PATH" ]; then
        wget -4 -O $DOWNLOAD_PATH -c $URL || exit 1
    fi
}

function decompress()
{
    rm -rf $SRC_PATH
    mkdir -p $SRC_PATH
    pushd $SRC_PATH
    unzip  $DOWNLOAD_PATH
    popd
}


function config()
{
    rm -rf $OBJ_PATH
    mkdir -p $OBJ_PATH
    pushd $OBJ_PATH
    echo CC="$BUILD_CC" cmake -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PATH $SRC_PATH/librealsense-master  -DBUILD_SHARED_LIBS=NO -DCMAKE_BUILD_TYPE=release
    CC="$BUILD_CC" cmake -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PATH $SRC_PATH/librealsense-master -DBUILD_SHARED_LIBS=NO -DCMAKE_BUILD_TYPE=release
    popd

  #ps:cmake - DBUILD_SHARED_LIBS=NO -DCMAKE_BUILD_TYPE=release 指定生成静态库
}

function compile()
{

    pushd $OBJ_PATH
    echo CFLAGS="$CFLAGS" CC="$BUILD_CC -I$INSTALL_PATH/include -L$INSTALL_PATH/lib" make   
    CFLAGS="$CFLAGS" CC="$BUILD_CC " 
    make
    popd

}

function install()
{

    pushd $OBJ_PATH
    make install
    popd

    mkdir -p $CONAN_PATH
    cp -f $INSTALL_PATH/lib/librealsense2.a $CONAN_PATH
}


case $1 in
download)
    download
    ;;
decompress)
    decompress
    ;;
config)
    config
   ;;
compile)
    compile
    ;;
install)
    install
    ;;
*)
    echo "$0 (download|decompress|config|compile|install)"
    ;;
esac


ps:多行脚本注释命令

<

内容

xxxx

你可能感兴趣的:(ubuntu,linux,运维)