Building Swift Barcode Reader with DBR 5.2 for Linux

Environment

Operating system and SDK

How to enable a shared folder in VMware

lsb_release -a
git clone https://github.com/rasa/vmware-tools-patches.gitcd vmware-tools-patchessudo ./patched-open-vm-tools.shsudo vmware-config-tools.plsudo reboot
swift xxx.swift
swiftc test.swift/usr/bin/ld.gold: fatal error: test: Input/output errorclang: error: linker command failed with exit code 1 (use -v to see invocation)<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

How to solve swiftc issue: “<unknown>:0: error: link command failed with exit code 127 (use -v to see invocation)”

sudo apt-get install clang libicu-dev
sudo apt-get install -y libicu-devsudo apt-get install -y clang-3.6sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100

Creating Swift Barcode Reader with C library

#include "DynamsoftBarcodeReader.h"int initLicense(const char* pszLicense);char* decodeFile(const char* pFileName, int iFormat);int createDBR();void destroyDBR();
#include <stdio.h>#include "dbr.h"#define DBR_NO_MEMORY 0#define DBR_SUCCESS   1// Barcode reader handlervoid* hBarcode = NULL;/*** Create DBR instance*/int createDBR(){if (!hBarcode) {hBarcode = DBR_CreateInstance();if (!hBarcode){printf("Cannot allocate memory!\n");return DBR_NO_MEMORY;}}return DBR_SUCCESS;}/*** Destroy DBR instance*/void destroyDBR(){if (hBarcode) {DBR_DestroyInstance(hBarcode);}}/*** Set Dynamsoft Barcode Reader license.* To get valid license, please contact support@dynamsoft.com* Invalid license is acceptable. With an invalid license, SDK will return an imcomplete result.*/int initLicense(const char* pszLicense){if (!createDBR()){return -1;}return DBR_InitLicenseEx(hBarcode, pszLicense);}char* createPyResults(SBarcodeResultArray *pResults){// Get barcode resultsint count = pResults->iBarcodeCount;SBarcodeResult** ppBarcodes = pResults->ppBarcodes;SBarcodeResult* tmp = NULL;int i = 0;for (; i < count; i++){tmp = ppBarcodes[i];printf("Result: %s, Format: %s\n", tmp->pBarcodeData, tmp->pBarcodeFormatString);}// Release memoryDBR_FreeBarcodeResults(&pResults);return NULL;}/*** Decode barcode from a file*/char* decodeFile(const char* pFileName, int iFormat){if (!createDBR()){return NULL;}// Initialize Dynamsoft Barcode Readerint iMaxCount = 0x7FFFFFFF;SBarcodeResultArray *pResults = NULL;DBR_SetBarcodeFormats(hBarcode, iFormat);DBR_SetMaxBarcodesNumPerPage(hBarcode, iMaxCount);// Barcode detectionint ret = DBR_DecodeFileEx(hBarcode, pFileName, &pResults);// Wrap resultsreturn createPyResults(pResults);}
let count = CommandLine.arguments.countif count < 2 {print("Please add a file name. E.g. ./barcode test.tif")}else {let fileName = CommandLine.arguments[1]createDBR()let ret = initLicense("t0068MgAAAGvV3VqfqOzkuVGi7x/PFfZUQoUyJOakuduaSEoI2Pc8+kMwjrojxQgE5aJphmhagRmq/S9lppTkM4w3qCQezxk=")if ret == 0 {// Read barcodelet barcodeTypes : Int32 = 0x3FF | 0x2000000 | 0x8000000 |0x4000000;  // 1D, QRCODE, PDF417, DataMatrixdecodeFile(fileName, barcodeTypes);}destroyDBR()}
gcc -c dbr.c
swiftc -import-objc-header dbr.h barcode.swift dbr.o -o barcode -lDynamsoftBarcodeReader
./barcode test.tif

Source Code

--

--

--

Manager of Dynamsoft Open Source Projects | Tech Lover

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Alvin’s Dew Drop Daily — Issue #36

AWS Privatelink — A Satellite View

Create your own media streaming platform [Using Open source technologies]

To Buy or to Build?: The Healthcare Technology Conundrum

Metis-edu, a powdered learning platform for everyone

Integrating AWS SQS and AWS Lambda function with a Node Application — Part 1

CS371p Fall 2020: Jessica Ma

Database Management System(DBMS)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xiao Ling

Xiao Ling

Manager of Dynamsoft Open Source Projects | Tech Lover

More from Medium

Should we write unit tests for network classes?

On M1, Build iOS Simulator Test APP Got “…for architecture arm64” Error

Batch Convert XCode String files, from utf-16 to utf-8

Implement an iOS Pipeline for an Hello World application by the use of Fastlane, Jenkins and App…