Calling the Linux C Library from C++ code

Here’s a quick example of how to create and build a simple C++ program that calls the basic Bardecode C library functions…

It’s assumed that you have already downloaded the Linux version of our SDK and are working in the installation folder.

The code:

#include

using namespace std;

extern “C” {
#include “include/barcode.h”
}

int main()
{
void *hBarcode = STCreateBarCodeSession();

char **bartype ;
char **barvalue ;
int n = STReadBarCode(hBarcode, (char *) “images/code39_01.tif”, (char *) “tif”, &barvalue, &bartype);

cout << "Return value = " ; cout << n ; cout << "\n"; if (n > 0)
{
cout << "First barcode value is "; cout << barvalue[0]; cout << "\n"; } return 0 ; } The build (you will have to get the path right for the various libraries - we built this on Ubuntu x64): g++ -o yourcode yourcode.cpp lib/bardecode.a /usr/lib/x86_64-linux-gnu/libtiff.so.5 /usr/lib/x86_64-linux-gnu/libjpeg.so.8 /usr/lib/x86_64-linux-gnu/libpthread.so