Dynamsoft Barcode Reader for Linux is released as a .tar.gz file. To use the barcode SDK, first, you have to download and extract the compressed package. Then, copy the shared libraries to /usr/lib folder or export the library search path. The process seems to be easy, but as a matter of fact, some developers who are new to Linux platform always suffer from the issue – shared library not found. To simplify the SDK installation and deployment, I decided to create a Debian package.
Making Debian Package
Basic Project Structure
Create a Debian package project as follows:
· Dbr_5.2: conform to the convention <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb, dbr is the package name and 5.2 is the version number.
· DEBIAN: the folder contains a control file and other script files. The control file provides the information about the package. Once the package has been unpacked, the DEBIAN postinst file will be triggered. If you want to run some commands before removing the package, add scripts to DEBIAN prerm file.
· Opt: all resources will be copied to /opt/ folder of the file system after installing the Debian package.
Download Dynamsoft Barcode Reader for Linux and extract all files to dbr_5.2/opt/dynamsoft/dbr.
DEBIAN control file
Edit the DEBIAN control file:
Package: dbr Version: 5.2 Architecture: amd64 Description: Dynamsoft Barcode Reader Dynamsoft Barcode Reader SDK for Linux enables you to efficiently embed barcode reading functionality into your web and desktop applications with a few lines of code. To get a valid trial license, please contact support@dynamsoft.com Maintainer: Dynamsoft <support@dynamsoft.com> Homepage: https://www.dynamsoft.com/Products/Dynamic-Barcode-Reader.aspx
The architectures include i386 for 32-bit Intel CPUs, amd64 for 64-bit, armel for ARM processors.
How to list the default library search path on Linux?
The error message “shared library not found” means the library does not exist under the default search paths. According to the answer from StackOverflow, we can use the following command to check the default search path:
ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012 SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu") SEARCH_DIR("=/lib/x86_64-linux-gnu") SEARCH_DIR("=/usr/lib/x86_64-linux-gnu") SEARCH_DIR("=/usr/local/lib64") SEARCH_DIR("=/lib64") SEARCH_DIR("=/usr/lib64") SEARCH_DIR("=/usr/local/lib") SEARCH_DIR("=/lib") SEARCH_DIR("=/usr/lib") SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64") SEARCH_DIR("=/usr/x86_64-linux-gnu/lib")
Usually, we can create a symbolic link for target shared library and move the symlink to /usr/lib/.
DEBIAN postinst
Create symbolic links for shared libraries in this file:
#!/bin/sh ln -s /opt/dynamsoft/dbr/lib/libDynamicPdf.so /usr/lib/libDynamicPdf.so ln -s /opt/dynamsoft/dbr/lib/libDynamsoftBarcodeReader.so /usr/lib/libDynamsoftBarcodeReader.so
DEBIAN prerm
Before uninstalling Debian package, remember to delete the related symlinks:
#!/bin/sh rm /usr/lib/libDynamicPdf.so rm /usr/lib/libDynamsoftBarcodeReader.so
Build, install and remove the Debian package
Build:
dpkg-deb -b dbr_5.2
Install:
sudo dpkg -i dbr_5.2.deb
Remove :
sudo dpkg -r dbr
Build a barcode project
After installing the .deb file with dpkg, you can build and run your barcode applications without specifying the library path:
g++ -o BarcodeReader -I/opt/dynamsoft/dbr/include/ BarcodeReader.cxx -lDynamsoftBarcodeReader ./BarcodeReader
Reference
Download
The post Building Debian Package for Dynamsoft Barcode SDK appeared first on Code Pool.