This example shows how to build and run a C++ command-line app that reads barcodes/QR codes from:
- A single image/PDF/TIFF file
- A directory (processed recursively)
- Multiple paths passed in one command
The app is implemented in main.cpp and uses Dynamsoft Capture Vision Router with the PT_READ_BARCODES preset template.
The sample accepts these file extensions:
.jpg,.jpeg,.png,.bmp,.gif.tif,.tiff.pdf
From this folder (examples/command-line):
mkdir -p build
cd build
cmake ..
cmake --build . --config ReleaseAfter building, the executable is generated in build/:
- Linux/macOS:
./main - Windows:
./Release/main.exe(or./main.exedepending on generator)
During post-build steps, required Dynamsoft libraries,
Templates/, andModels/are copied next to the executable automatically.
./main ../single_page.tif./main ../../images./main ../single_page.tif ../multi_page.tif ../../imagesIf no arguments are provided, the app enters interactive mode:
./mainThen type a full file or directory path. Enter q to quit.
- Single file: prints detailed results (format, text, and quadrilateral points per barcode).
- Directory: prints per-file summary and directory statistics.
- Multiple inputs: prints per-input results and an overall summary.
The demo initializes a trial license in source code. For production use, replace it with your own key in main.cpp:
CLicenseManager::InitLicense("LICENSE-KEY", szErrorMsg, 256);Get a trial license here:
single_page.tifmulti_page.tifmulti_page.pdftest.pdf
You can use these files to quickly validate decoding.
Building a Cross-platform Command-line Barcode and QR Code Reader in C++