| gclib 1.35.5 Communications API for Galil controllers and PLCs |

Rebuilding gclibo

gclib ships with a compiled version of the open source portion, gclibo. However, if a source modification is desired, the following instructions will help with recompiling this portion of the library.

# Windows

For brevity, these instructions assume the default installation location of C:\Program Files (x86)\Galil\gclib and a build type of x86 (win32). The following instructions were performed on Visual Studio Professional 2015 and can be extended to other Visual Studio versions.

## Preparation

Create a working directory. A convenient, empty, writable location, e.g.

    C:\>mkdir %homepath%\Desktop\temp

Note
  In this documentation, a single greater-than character (>) will indicate a command prompt at this working directory.

Recompiling gclibo requires the source code for the open source compression library zlib. This can be downloaded from the zlib website: http://zlib.net/zlib1211.zip.

Extract the downloaded zlib source files to the working directory.

Open VS2015 x86 Native Tools Command Prompt and navigate to the working directory.

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>cd %homepath%\Desktop\temp
    C:\Users\user\Desktop\temp>dir /b
    zlib-1.2.11

## Copy files

### Set an environment variable for the base path.

    >set base="C:\Program Files (x86)\Galil\gclib"

### Set an environment variable for the zlib base path.

    >set zlib="%CD%\zlib-1.2.11"

### Copy the gclibo source files.

    >copy %base%\source\gclibo\*.c .
    C:\Program Files (x86)\Galil\gclib\source\gclibo\arrays.c
    C:\Program Files (x86)\Galil\gclib\source\gclibo\gclibo.c
            2 file(s) copied.

## Modify source

Make any necessary changes. For this example, the GInfo() function was changed from

GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
{
return GUtility(g, G_UTIL_INFO, info, &info_len);
}
GUtility
GCLIB_DLL_EXPORTED GReturn GCALL GUtility(GCon g, GOption request, GMemory memory1, GMemory memory2)
Provides read/write access to driver settings and convenience features based on the request variable.
GInfo
GCLIB_DLL_EXPORTED GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
Uses GUtility() and G_UTIL_INFO to provide a useful connection string.
Definition: gclibo.c:49
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
G_UTIL_INFO
#define G_UTIL_INFO
GUtility(), get a connection info string.
Definition: gclib.h:63
GSize
unsigned int GSize
Size of buffers, etc.
Definition: gclib.h:95
GCALL
#define GCALL
Specify calling convention for Windows.
Definition: gclib.h:38
GCon
void * GCon
Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
Definition: gclib.h:94
GCStringOut
char * GCStringOut
C-string output from the library. Implies null-termination.
Definition: gclib.h:97

to

GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
{
strncpy(info, "My controller", info_len);
return G_NO_ERROR;
//return GUtility(g, G_UTIL_INFO, info, &info_len);
}
G_NO_ERROR
#define G_NO_ERROR
Return value if function succeeded.
Definition: gclib_errors.h:13

## Compile and copy

### Compile the source code.

    >cl -c *.c %zlib%\*.c -I %base%\include -I %zlib% -DBUILDING_GCLIB

### Link the binaries.

    >link /DLL *.obj %base%\lib\dynamic\x86\gclib.lib /OUT:gclibo.dll

### Copy

Copy back to the installation location from the file explorer. This will require administrator privileges.

- Copy gclibo.lib to "C:\Program Files (x86)\Galil\gclib\lib\dynamic\x86"
- Copy gclibo.dll to "C:\Program Files (x86)\Galil\gclib\dll\x86"

## Test

### Copy simple example

    >copy %base%\examples\cpp\x_simple.c .

### Edit GOpen() call as necessary.

### Compile

    >cl x_simple.c %base%\lib\dynamic\x86\*.lib -I %base%\include

### Set Path to DLL

    >set PATH=%base%\dll\x86\;%PATH%

### Execute

    >x_simple.exe
    rc: 0
    version: 85.60.138
    rc: 0
    rc: 0
    info: My controller
    rc: 0
    response:  355000958.0000
    :

# Linux

Recompiling gclibo requires the source code for the open source compression library zlib. Make will automatically download the needed project from the zlib website: https://www.zlib.net/.

## Copy files

    $ mkdir test
    $ cd test
    $ tar -xzf /usr/share/doc/gclib/src/gclibo_src.tar.gz
    $ cp /usr/include/gclib*.h .

## Modify source

Make any necessary changes. For this example, the GInfo() function was changed from

GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
{
return GUtility(g, G_UTIL_INFO, info, &info_len);
}

to

GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
{
strncpy(info, "My controller", info_len);
return G_NO_ERROR;
//return GUtility(g, G_UTIL_INFO, info, &info_len);
}

## Make and install

    # make install -f makefile_gclibo
    Acquiring zlib
    wget -q http://zlib.net/zlib-1.2.11.tar.gz
    shasum -a 256 -c zlib.sha256
    zlib-1.2.11.tar.gz: OK
    tar -xzf zlib-1.2.11.tar.gz
    Compiling zlib
    gcc -c -Wall -w -fPIC -fvisibility=hidden -DBUILDING_GCLIB -DHAVE_VISIBILITY zlib-1.2.11/*.c
    Compiling open source component, libgclibo.so.0.0
    gcc -Izlib-1.2.11 -c -Wall -Werror -fPIC -fvisibility=hidden -DBUILDING_GCLIB -DHAVE_VISIBILITY gclibo.c arrays.c
    Linking open source component into shared library.
    gcc -shared -o libgclibo.so.0.0 *.o -lgclib -L. -Wl,-rpath=/usr/lib -Wl,-soname=libgclibo.so.0
    strip --strip-unneeded libgclibo.so.0.0
    Installing libgclibo.so.0.0
    install -m 755 libgclibo.so.0.0 /usr/lib
    ldconfig
    # make clean -f makefile_gclibo
    Cleaning project...

## Test

### Extract simple example

    $ tar -xzf /usr/share/doc/gclib/src/gclib_examples.tar.gz x_simple.c

### Edit GOpen() call as necessary.

### Compile

    $ gcc x_simple.c -Wall -Werror -lgclib -lgclibo -o simple

### Execute

    $ ./simple
    rc: 0
    version: 85.60.131
    rc: 0
    rc: 0
    info: My controller
    rc: 0
    response:  182879322.0000
    :

# OS X

## Copy files

    $ mkdir test
    $ cd test
    $ tar -xvf /Applications/gclib/source/gclibo_src.tar.gz x gclibo.h
    x gclibo.c
    x arrays.c
    x makefile_gclibo
    $ cp /Applications/gclib/include/* .
    $ cp /Applications/gclib/dylib/gclib.0.dylib .
    $ ls
    arrays.c  gclib.h   gclib_record.h  gclibo.h
    gclib.0.dylib gclib_errors.h  gclibo.c  makefile_gclibo

## Modify source

Make any necessary changes. For this example, the GInfo() function was changed from

GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
{
return GUtility(g, G_UTIL_INFO, info, &info_len);
}

to

GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
{
strncpy(info, "My controller", info_len);
return G_NO_ERROR;
//return GUtility(g, G_UTIL_INFO, info, &info_len);
}

## Make and install

    $ make -f makefile_gclibo
    Open source component, gclibo.0.dylib
      Compiling open source component.
    gcc -c -Wall -Werror -fPIC -fvisibility=hidden -DBUILDING_GCLIB -DHAVE_VISIBILITY *.c
      Linking open source component into shared library.
    gcc -dynamiclib -o gclibo.0.dylib *.o gclib.0.dylib
    strip -u -r gclibo.0.dylib
      Cleaning up.
    $ make install -f makefile_gclibo
    Installing gclibo.0.dylib
    cp gclibo.0.dylib /Applications/gclib/dylib
    $ make clean -f makefile_gclibo
    Cleaning project...

## Test

### Extract simple example

    $ tar -xzf /Applications/gclib/examples/gclib_examples.tar.gz x_simple.c

### Edit GOpen() call as necessary.

### Compile

    $ gcc x_simple.c -Wall -Werror gclib.0.dylib gclibo.0.dylib -o simple

### Execute

    $ ./simple
    rc: 0
    version: 127.110.253
    rc: 0
    rc: 0
    info: My controller
    rc: 0
    response:  182879322.0000
    :