1. 程式人生 > 實用技巧 >Ubuntu 18安裝librealsense

Ubuntu 18安裝librealsense

  寫在前面

    今天看到QQ“那年今日”提醒,三年前的今天我給自己寫了一句話:等待機遇的同事不忘繼續努力,走太遠,別忘了為什麼出發。

  對於記錄個人生活而言,QQ比微信優秀太多了。可惜膨脹了,加了一大堆小眾的功能,使用者體驗直線下降……額,扯遠了。言歸正傳。

    因為專案是C++程式碼寫的,之前裝的Python版本的realsense庫用不上了,只能build一個librealsense。

    由於前些天安裝opencv安裝怕了,怎麼make怎麼不行,所以聽到partner說安裝librealsense和opencv一樣難搞時,我怯了。

    可事情總得去做,才有可能做成,對吧?

    安裝之前,確保電腦沒有接realsense裝置。

    電腦系統:Ubuntu 18.04.4 LTS

    安裝方法參考https://github.com/IntelRealSense/librealsense

    command:

git clone https://github.com/Microsoft/vcpkg.git

cd vcpkg

./bootstrap-vcpkg.sh

./vcpkg integrate install

./vcpkg install realsense2

    執行命令 ./bootstrap-vcpkg.sh 的時候會下載3個包:cmake、librealsense、ninja。

  下載過程比較慢,也許會失敗,報錯“過早的檔案結束符(EOF)”之類的,此命令多執行幾次,就可以下載好了。箇中緣由,我歸結為網路不好?

ljx@ljx-Lenovo:~/soft/vcpkg$ ./bootstrap-vcpkg.sh 
Extracting cmake...
Extracting cmake... done.
Downloading ninja...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 624 100 624 0 0 181 0 0:00:03 0:00:03 --:--:-- 181 100 99857 100 99857 0 0 4844 0 0:00:20 0:00:20 --:--:-- 10906 Downloading ninja... done. Extracting ninja... Extracting ninja... done. -- The CXX compiler identification is GNU 7.5.0 -- Check for working CXX compiler: /usr/bin/g++-7 -- Check for working CXX compiler: /usr/bin/g++-7 - works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Detecting the C++ compiler in use -- Detecting the C++ compiler in use - gcc -- Detecting the C++ standard library -- Detecting the C++ standard library - libstdc++ -- Detecting how to use the C++ filesystem library -- Detecting how to use the C++ filesystem library - <experimental/filesystem> with -l[std]c++fs -- Looking for C++ include pthread.h -- Looking for C++ include pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - yes -- Found Threads: TRUE -- Configuring done -- Generating done -- Build files have been written to: /home/ljx/soft/vcpkg/toolsrc/build.rel [0/2] Re-checking globbed directories... [79/79] Linking CXX executable vcpkg Telemetry --------- vcpkg collects usage data in order to help us improve your experience. The data collected by Microsoft is anonymous. You can opt-out of telemetry by re-running the bootstrap-vcpkg script with -disableMetrics, passing --disable-metrics to vcpkg on the command line, or by setting the VCPKG_DISABLE_METRICS environment variable. Read more about vcpkg telemetry at docs/about/privacy.md ljx@ljx-Lenovo:~/soft/vcpkg$ ./vcpkg integrate install Applied user-wide integration for this vcpkg root. CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=/home/ljx/soft/vcpkg/scripts/buildsystems/vcpkg.cmake"

  命令執行過程如上圖,應該是沒問題的。

  但我在執行./vcpkg install realsense2的時候報錯:

-- Configuring x64-linux-dbg
-- Configuring x64-linux-rel
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:72 (message):
Command failed: /home/ljx/soft/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake /home/ljx/soft/vcpkg/buildtrees/realsense2/src/93b7ff8597-4347a45ee5.clean -DBUILD_WITH_TM2=OFF -DENFORCE_METADATA=ON -DBUILD_WITH_OPENMP=OFF -DBUILD_UNIT_TESTS=OFF -DBUILD_WITH_STATIC_CRT=0 -DBUILD_OPENNI2_BINDINGS=OFF -DOPENNI2_DIR=/home/ljx/soft/vcpkg/installed/x64-linux/include/openni2 -DCMAKE_MAKE_PROGRAM=/home/ljx/soft/vcpkg/downloads/tools/ninja-1.10.0-linux/ninja -DCMAKE_SYSTEM_NAME=Linux -DBUILD_SHARED_LIBS=OFF -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/home/ljx/soft/vcpkg/scripts/toolchains/linux.cmake -DVCPKG_TARGET_TRIPLET=x64-linux -DVCPKG_SET_CHARSET_FLAG=ON -DVCPKG_PLATFORM_TOOLSET=external -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE -DCMAKE_VERBOSE_MAKEFILE=ON -DVCPKG_APPLOCAL_DEPS=OFF -DCMAKE_TOOLCHAIN_FILE=/home/ljx/soft/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON -DVCPKG_CXX_FLAGS= -DVCPKG_CXX_FLAGS_RELEASE= -DVCPKG_CXX_FLAGS_DEBUG= -DVCPKG_C_FLAGS= -DVCPKG_C_FLAGS_RELEASE= -DVCPKG_C_FLAGS_DEBUG= -DVCPKG_CRT_LINKAGE=dynamic -DVCPKG_LINKER_FLAGS= -DVCPKG_TARGET_ARCHITECTURE=x64 -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_BINDIR:STRING=bin -D_VCPKG_ROOT_DIR=/home/ljx/soft/vcpkg -D_VCPKG_INSTALLED_DIR=/home/ljx/soft/vcpkg/installed -DVCPKG_MANIFEST_INSTALL=OFF -DBUILD_EXAMPLES=OFF -DBUILD_GRAPHICAL_EXAMPLES=OFF -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/ljx/soft/vcpkg/packages/realsense2_x64-linux
Working Directory: /home/ljx/soft/vcpkg/buildtrees/realsense2/x64-linux-rel
/home/ljx/soft/vcpkg/buildtrees/realsense2/x64-linux-rel Error code: 1 See logs for more information: /home/ljx/soft/vcpkg/buildtrees/realsense2/config-x64-linux-rel-out.log /home/ljx/soft/vcpkg/buildtrees/realsense2/config-x64-linux-rel-err.log Call Stack (most recent call first): scripts/cmake/vcpkg_configure_cmake.cmake:319 (vcpkg_execute_required_process) ports/realsense2/portfile.cmake:29 (vcpkg_configure_cmake) scripts/ports.cmake:79 (include) Error: Building package realsense2:x64-linux failed with: BUILD_FAILED Please ensure you're using the latest portfiles with `.\vcpkg update`, then submit an issue at https://github.com/Microsoft/vcpkg/issues including: Package: realsense2:x64-linux Vcpkg version: 2020.06.15-unknownhash Additionally, attach any relevant sections from the log files above.

    我複製保留了執行./bootstrap-vcpkg.sh 的時候下載的3個包:cmake、librealsense、ninja,(在vcpkg/downloads裡面),清除vcpkg資料夾,

  重新按那幾條指令順序走一遍,在執行./bootstrap-vcpkg.sh 之前把三個下好的包放回對應的資料夾(純粹是因為這樣不用漫長的等待),

  好了,依舊是最後一步出錯。

    然後我想能不能不用vcpkg這個C++包管理器安裝,畢竟我已經通過它下載好了librealsense。

  於是我找到了https://github.com/IntelRealSense/librealsense/blob/v2.38.0/doc/installation.md,看到了Building librealsense2 SDK,看到了cmake……

  接著解壓剛才下載好的IntrlRealSense-librealsense

  一頓操作:

mkdir build
cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release
sudo make uninstall && make clean && make && sudo make install

  等待一段時間,輸入sudo密碼繼續安裝完成,就好了

  

  專案成功include啦!

  至此,librealsense安裝完成。

  你以為的困難,不一定就真的難。