Skip to the content.
English 한국어 日本語 Tiếng Việt

COBOL example

https://github.com/bobhyun/TS-ANPR/tree/main/examples/COBOL/anpr

This example demonstrates how to integrate the TS-ANPR engine with COBOL applications using a C wrapper library.

Architecture

The COBOL example uses a layered architecture:

COBOL Application (anpr.cbl)
         ↓
C Wrapper Library (libtsanpr_cobol.so/.dll)
         ↓
TS-ANPR Engine (libtsanpr.so/tsanpr.dll)

1. Copying the Engine Files

[Note] In this example, the engine file is extracted to the examples/bin/ directory to share it with other examples. However, for actual deployment, the engine file is typically copied to the directory where the application’s executable file is located.

2. Build and Run

2.1 Windows

  1. GnuCOBOL Installation

  2. GCC Installation

    • GCC is required to build the C wrapper
    • If you installed SuperBOL, MinGW64 GCC is already included
    • Otherwise, install MinGW-w64
  3. How to Build

    compile.bat
    

    Or using Make:

    make
    
  4. How to Run

    run.bat
    

    Or using Make:

    make run
    

2.2 Linux

  1. Dependency Installation

    • Debian / Ubuntu Linux

      sudo apt-get update
      sudo apt-get install gnucobol gcc
      
    • Oracle Linux / RedHat (RHEL) / CentOS

      sudo yum install gnucobol gcc
      
    • Fedora

      sudo dnf install gnucobol gcc
      
  2. How to Build

    chmod +x compile.sh
    ./compile.sh
    

    Or using Make:

    make
    
  3. How to Run

    chmod +x run.sh
    ./run.sh
    

    Or using Make:

    make run
    

Implementation Details

C Wrapper (src/c/tsanpr_cobol.c)

The C wrapper provides three main functions:

The wrapper handles:

COBOL Program (src/cobol/anpr.cbl)

The COBOL program demonstrates:

All features match the functionality of examples in other languages (C, Python, etc.).

Performance Notes

For better performance on WSL, copy the entire project to the WSL native filesystem (e.g., ~/).

Troubleshooting

Linux: “libcob: error: module not found”

This error occurs when GnuCOBOL cannot find the C wrapper library. The run script uses LD_PRELOAD to force load the library.

Solution: Always use run.sh or make run instead of running the binary directly.

Windows: DLL not found error

Ensure that:

  1. bin/tsanpr_cobol.dll exists after compilation
  2. You’re running via run.bat which sets COB_LIBRARY_PATH

License

This example code is released under the MIT License.