Requirements

Linux
x86 x64
Header files If_DBRP.h
BarcodeFormat.h
BarcodeStructs.h
CommonConfig.h
ErrorCode.h
ExportDefines.h
If_DBRP.h
BarcodeFormat.h
BarcodeStructs.h
CommonConfig.h
ErrorCode.h
ExportDefines.h
Lib Files libDynamsoftBarcodeReaderx86.so libDynamsoftBarcodeReaderx64.so

Three Steps to Get Started

  1. Suppose you are creating a project in a folder called test.

    Create a test.cpp file in folder "test" and copy the "Include" and "Redist" folders from the SDK package to "test"

    In the test.cpp, please include the .h files.

    Please replace <relative path> in the code with the relative path to the test.cpp file.
    #include <stdio.h>
    #include "<relative path>/If_DBRP.h"

  2. In the test.cpp, please add the main function.

    Please update the <your image file full path> and <your license key here> with valid values respectively in the code.

    The licenses can be found in the [INSTALL FOLDER]/TrialLicense.txt.
    int main(int argc, const char* argv[])
    {
        //Define variables
        const char * pszImageFile = "<your image file full path>";
        int iIndex = 0;
        int iRet = -1;
        //Initialize license prior to any decoding
        CBarcodeReader reader;
        reader.InitLicense("<your license key here>");
    
        //Start decoding
        iRet = reader.DecodeFile(pszImageFile);
    
        //If error occurs
        if (iRet != DBR_OK)
        {
            printf("Failed to read barcode: %d\n%s\n", iRet, DBR_GetErrorString(iRet));
            return iRet;
        }
        //If OK
        pBarcodeResultArray paryResult = NULL;
        reader.GetBarcodes(&paryResult);
        printf("%d total barcodes found. \r\n", paryResult->iBarcodeCount);
        for (iIndex = 0; iIndex < paryResult->iBarcodeCount; iIndex++)
        {
            printf("Result %d\r\n", iIndex + 1);
            printf("PageNum: %d\r\n", paryResult->ppBarcodes[iIndex]->iPageNum);
            printf("BarcodeFormat: %lld\r\n", paryResult->ppBarcodes[iIndex]->llFormat);
            printf("Text read: %s\r\n", paryResult->ppBarcodes[iIndex]->pBarcodeData);
        }
    
        //Finally release BarcodeResultArray
        DBR_FreeBarcodeResults(&paryResult);
    
        return 0;
    }
  3. Create a Makefile in the folder "test", replace <your project name> to test:
    ProjectName=<your project name>
    CC=gcc
    CCFLAGS=-c
    
    DBRLIB_PATH=./Redist
    LDFLAGS=-L $(DBRLIB_PATH) -Wl,-rpath=$(DBRLIB_PATH)
    
    ifeq ($(shell getconf LONG_BIT), 32)
    DBRLIB=-lDynamsoftBarcodeReaderx86
    else
    DBRLIB=-lDynamsoftBarcodeReaderx64
    endif
    
    STDLIB=-lstdc++
    
    TARGET=$(ProjectName)
    OBJECT=$(ProjectName).o
    SOURCE=$(ProjectName).cpp
    
    # build rule for target.
    $(TARGET): $(OBJECT)
    	$(CC) -o $(TARGET) $(OBJECT) $(STDLIB) $(DBRLIB) $(LDFLAGS)
    
    # target to build an object file
    $(OBJECT): $(SOURCE)
    	$(CC) $(CCFLAGS) $(SOURCE)
    
    # the clean target
    .PHONY : clean
    clean: 
    	rm -f $(OBJECT) $(TARGET)

    Please open a terminal, and navigate to the test folder to do the following to verify if it is working.
    $ make
    $./test