ld找不到動態函式庫的除錯方法

注意是否有從C++ 呼叫C語言的函式,如果有必須要使用extern C

https://hackmd.io/@rhythm/HyOxzDkmD

https://www.airs.com/blog/archives/38

https://www.google.com/search?q=Linkers+part+site%3Ahttps%3A%2F%2Fwww.airs.com%2F&rlz=1C1GCEU_zh-TWTW902TW902&oq=Linkers+part+site%3Ahttps%3A%2F%2Fwww.airs.com%2F&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBCDM1ODlqMGo3qAIAsAIA&sourceid=chrome&ie=UTF-8#ip=1

注意function是否為static function

c語言中的static function在function被定義的檔案以外的scope是看不到的

undefined reference to

表示必要的函式庫或是.o檔沒有被連接

  1. nm指令確認函式確實存在.so檔裡面例如:
    nm -D libnvds_utils.so --defined-only的輸出如下,這個指令只會列出有對外開放的函式
    1
    2
    3
    4
    5
    6
    0000000000001470 T nvds_dependencies_version_print
    00000000000018d0 T nvds_mask_utils_resize_to_binary_argb32
    00000000000013f0 T nvds_version
    0000000000001410 T nvds_version_print
    0000000000001310 T _Z18libnvds_utils_initv
    0000000000001300 T _Z20libnvds_utils_deinitv
    https://stackoverflow.com/a/4514781
  • nm不只可以用在函式庫檔,.o檔也可以用
    nm deepstream_source_bin.o --defined-only
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    0000000000000000 b install_mux_eosmonitor_probe
    0000000000000010 b last_reset_time_global.31491
    0000000000000008 b mutex.31460
    00000000000030a8 t nvstreammux_eosmonitor_probe_func
    0000000000006ab0 T reset_encodebin
    00000000000065e8 T reset_source_pipeline
    000000000000133c t restart_stream_buf_prob
    0000000000002ffc t rtspsrc_monitor_probe_func
    0000000000001270 t seek_decode
    0000000000000020 t set_camera_csi_params
    00000000000000bc t set_camera_v4l2_params
    0000000000006a04 T set_source_to_playing
    0000000000002178 t smart_record_callback
    0000000000002270 t smart_record_event_generator
    0000000000002e74 t watch_source_async_state_change
    00000000000026d0 t watch_source_status
    ...

/usr/bin/ld: cannot find …

編譯過程中發現ld找不到某個函式庫例如/usr/bin/ld: cannot find -ljpeg,可以利用指令ld <函式庫> --verbose可以查看ld找了那些路徑,例如目前ld找不到-ljpeg可以利用ld -ljpeg --verbose,輸出如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ld: mode aarch64linux
attempt to open /usr/local/lib/aarch64-linux-gnu/libjpeg.so failed
attempt to open /usr/local/lib/aarch64-linux-gnu/libjpeg.a failed
attempt to open /lib/aarch64-linux-gnu/libjpeg.so failed
attempt to open /lib/aarch64-linux-gnu/libjpeg.a failed
attempt to open /usr/lib/aarch64-linux-gnu/libjpeg.so failed
attempt to open /usr/lib/aarch64-linux-gnu/libjpeg.a failed
attempt to open /usr/local/lib/libjpeg.so failed
attempt to open /usr/local/lib/libjpeg.a failed
attempt to open /lib/libjpeg.so failed
attempt to open /lib/libjpeg.a failed
attempt to open /usr/lib/libjpeg.so failed
attempt to open /usr/lib/libjpeg.a failed
attempt to open /usr/aarch64-linux-gnu/lib/libjpeg.so failed
attempt to open /usr/aarch64-linux-gnu/lib/libjpeg.a failed
ld: cannot find -ljpeg

注意makefile的擺放順序

連接器指令放最後面
例如

1
gcc -I/usr/local/include -o yaml_reader yaml_reader.c  -L/usr/local/lib -lfyaml

https://stackoverflow.com/questions/22426574/gcc-undefined-reference-to

https://stackoverflow.com/questions/16710047/usr-bin-ld-cannot-find-lnameofthelibrary

注意cmake是否有把程式加入編譯

add_executable(…)內加入的cpp檔會被編譯,確認是否有將程式加入

Jetson設定

  1. 遠端桌面
    Nomachine

  2. 硬體狀態jtop

    1
    2
    3
    sudo apt update
    sudo apt install python3-pip
    sudo pip3 install -U jetson-stats
  3. 關閉GUI節省GPU資源

  • 暫時關閉以及打開方法
    1
    sudo init 3  #暫時關閉
1
sudo init 5  #打開
  • 重啟後不再打開GUI
    1
    sudo systemctl set-default multi-user.target #關閉
1
sudo systemctl set-default multi-user.target #打開

參考:
https://forum.nomachine.com/topic/problems-connecting-with-nomachine-in-pc-client-without-monitor

Linux實用TUI

樹梅派列印機和掃描器伺服器

L3110-主要依照這篇
https://antivirus.com/2021/05/26/raspberry-pi-project-how-to-convert-a-usb-all-in-one-printer-to-a-wireless-printer/

下面方法解決問題並且成功列印測試頁。

1
2
sudo apt install printer-driver-escpr #安裝後解決
sudo apt install hplip #下次測試不安裝可不可以順利運作(epson)

https://forums.raspberrypi.com/viewtopic.php?t=225739

local列印成功後,設定網路

  • 開啟網路管理服務以及nmtui
    1
    2
    systemctl start NetworkManager
    sudo nmtui

不要設定AllowUser以免權限不足

如果發現錯誤,請在網頁AllowUser留白並且儲存

1
Returning IPP client-error-not-authorized for Create-Job (ipps://192.168.50.169:631/printers/epson_l3110_series) from 192.168.50.9.

https://askubuntu.com/a/708217

掃描器

使用SANE:Setting up a Raspberry Pi Scanner Server using SANE

安裝必要軟體後,檢查SANE能不能找到你的掃描器,如果不行就必須手動設定,方法如官網Helpful commands for Troubleshooting sane

網頁板掃描頁面

https://github.com/sbs20/scanservjs/tree/master

安裝後出現以下說明

1
2
3
4
5
6
7
Created symlink /etc/systemd/system/multi-user.target.wants/scanservjs.service → /etc/systemd/system/scanservjs.service.

scanservjs installed and running
http://127.0.0.1:8080

If you encounter problems when running, try
sudo journalctl -e -u scanservjs

桌面版軟體

安裝後在windows上面安裝前端軟體SaneTwain

其他參考:
https://ubuntu.com/server/docs/service-cups

airprint
https://www.developer.com/mobile/cups-and-raspberry-pi-airprinting/

https://unix.stackexchange.com/questions/394687/printer-drivers-required-if-cups-is-installed

Deepstream辨識結果遠端觀看

RTSP遠端觀看設定

可以參考這篇
特別注意如果Deepstream不是在Jetson上面跑記得要換成下面指令啟動server,因為dGPU的Deepstream沒有nvvidconv原件!!

1
./test-launch "videotestsrc is-live=1 ! videoconvert  ! x264enc ! h264parse ! rtph264pay name=pay0 pt=96"

整合到自己的程式裡

sources\apps\apps-common\src\deepstream_sink_bin.c有詳細的整合方式。

https://github.com/aler9/mediamtx#installation

Ubuntu安裝CUDA cuDNN TeosorRT

  1. 安裝CUDA
    將CUDA的repo加入apt
    1
    2
    3
    4
    5
    6
    wget https://developer.download.nvidia.com/compute/cuda/11.7.1/local_installers/cuda-repo-debian11-11-7-local_11.7.1-515.65.01-1_amd64.deb
    sudo dpkg -i cuda-repo-debian11-11-7-local_11.7.1-515.65.01-1_amd64.deb
    sudo rm /etc/apt/sources.list.d/*cuda*
    sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
    sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
    sudo apt-get update

接下來注意不要直接sudo apt-get -y install cuda,因為可能會直接安裝最新版的CUDA,而不是你指定的版本

首先確認有哪些版本可以下載

1
apt-cache policy vlc

輸出如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cuda:
Installed: (none)
Candidate: 12.1.1-1
Version table:
12.1.1-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
12.1.0-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
12.0.1-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
12.0.0-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
11.8.0-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
11.7.1-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
11.7.0-1 500
500 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 Packages
......

在這裡我們想安裝CUDA 11.7.1,指令如下

1
sudo apt-get  install cuda=11.7.1-1

再次確認即將安裝的是不是CUDA11.7,是的話再按y

  1. 安裝cuDNN和TensorRT
    1
    2
    3
    4
    5
    sudo apt-get install libnvinfer8=8.4.1-1+cuda11.6 libnvinfer-plugin8=8.4.1-1+cuda11.6 libnvparsers8=8.4.1-1+cuda11.6 \
    libnvonnxparsers8=8.4.1-1+cuda11.6 libnvinfer-bin=8.4.1-1+cuda11.6 libnvinfer-dev=8.4.1-1+cuda11.6 \
    libnvinfer-plugin-dev=8.4.1-1+cuda11.6 libnvparsers-dev=8.4.1-1+cuda11.6 libnvonnxparsers-dev=8.4.1-1+cuda11.6 \
    libnvinfer-samples=8.4.1-1+cuda11.6 libcudnn8=8.4.1.50-1+cuda11.6 libcudnn8-dev=8.4.1.50-1+cuda11.6 \
    python3-libnvinfer=8.4.1-1+cuda11.6 python3-libnvinfer-dev=8.4.1-1+cuda11.6

參考:
https://docs.nvidia.com/metropolis/deepstream/6.1.1/dev-guide/text/DS_Quickstart.html#

https://askubuntu.com/questions/340530/how-can-i-check-the-available-version-of-a-package-in-the-repositories

Ubuntu設定自動化安全性更新

  • install

    1
    sudo apt install unattended-upgrades
  • Verify

    1
    systemctl status unattended-upgrades
  • config

    1
    sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
  • Blacklist
    Unattended-Upgrade::Package-Blacklist

  • Email Notifications
    Unattended-Upgrade::Mail example@email.com;

Unattended-Upgrade::MailOnlyOnError “true”;

  • Enable Automatic Upgrades

    1
    sudo nano /etc/apt/apt.conf.d/20auto-upgrades
  • Testing Automatic Upgrades

    1
    sudo unattended-upgrades --dry-run --debug
  • check log

    1
    /var/log/unattended-upgrades/unattended-upgrades.log

參考:
https://phoenixnap.com/kb/automatic-security-updates-ubuntu

windows docker設定

docker image搬離開系統槽

https://stackoverflow.com/questions/62441307/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2

  1. 關閉wsl2

    1
    wsl --shutdown
  2. 匯出docke檔案

    1
    wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"
  3. unregister

    1
    wsl --unregister docker-desktop-data
  4. 匯入

    1
    wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2

wsl2 volume

https://stackoverflow.com/questions/61083772/where-are-docker-volumes-located-when-running-wsl-using-docker-desktop

Windows使用SOCKS5-proxy上網

簡介

這裡將介紹一個只需要使用SSH連線到一台可以連到對網網路的主機,就可以讓防火牆內的主機上網的方法
圖片說明

設定putty

https://www.simplified.guide/putty/create-socks-proxy

或是用ssh指令連接到可以上網的電腦

1
ssh -D 4444 -q -C -N user@ma.ttias.be

windows 設定SOCKS5 proxy

https://blog.gtwang.org/linux/ssh-tunnel-socks-proxy-forwarding-tutorial/

新增憑證

https://learn.microsoft.com/zh-tw/biztalk/adapters-and-accelerators/accelerator-swift/adding-certificates-to-the-certificates-store-on-the-client

windows下設定git proxy command

https://serverfault.com/questions/956613/windows-10-ssh-proxycommand-posix-spawn-no-such-file-or-directory