Building and Running Applications on Windows

The PI-API is built as a C/C++ library, but all function definitions and exports are ANSI C compatible. Thus, programs built with the PI-API may be compiled as C code. There is no assumption of compiler version, but it has only been tested with Microsoft compilers. The includes, libraries, paths, and preprocessor macros for compiling PI-API programs are discussed below.

Compilation with Predefined Constants

Certain predefined constants are required for successful programming with the PI-API. Each compiler may automatically define some of these macros and also provide a means to define additional constants. These defines must be included in your source before the PI-API header files are included.

For this platform the required PI-API preprocessor constants are:

/D "_WIN32"

All Windows, both Win32 and Win64. This is defined by Microsoft compilers automatically.

/D "WIN32"

Define for 32-bit and 64-bit Windows applications.

/D "_WIN64"

Defined for 64-bit Windows applications. This is defined by Microsoft compilers automatically.

/D "X64"

Define for 64-bit Windows applications. This must be defined for pidefs.h.

Include and Link Files and Paths

For use in projects, makefiles and scripts, the PI-API installation defines installation path environment variables for both the 32 and 64-bit distributions. These are PIHOME for the 32-bit and PIHOME64 for the 64-bit installation. These are only defined at installation. The include path for the PIAPI headers using these definitions is

The source code should include the file piapix.h. Additional include files are supplied that assist in making code more readable. These define error constants in pistatus.h, and system digital state values in pidgstat.h.

The linker needs the path and import library to create an executable:

Example Program

An example program and project, apisnap.c, are provided in the directory PIHOME\EXAMPLES\C. The makefile is a Visual C++ project makefile which builds a program that obtains the current value for a tag. If you are developing in MSVC, it is useful to review this program and the compiler settings established by the project.

Enabling Operational Intelligence