How to "fasten" CLIPS to a Linux application

The CLIPS (C-language Integrated Production System) product appeared in 1984 as an environment for developing expert systems for NASA projects. Despite the fact that this project was suspended, the developers continued to improve this environment - the latest update was released in 2006.

CLIPS provides integration into various applications written both in C and C ++, and in Java. Interestingly, the advanced programmer’s guide shows integration options for windows applications, but there’s not a word about integration with Linux applications.

In the process of writing a dissertation, I encountered the following problem: my expert system had to be run on a Linux-like OS, while the main application using the expert system had to be written in pure C. To check this possibility, Fedora was chosen, and all the code was written in ECLIPSE. Perhaps this experience may seem useful to someone.

To begin with, CLIPS offers the following integration options [1]:

1. Integration using open source.
The presence of open source implies that you need to recompile the entire project, "picking up" all the source files for it, and then you will have to directly access all the functions of the environment. The option was eliminated because in addition to connecting an expert system, it was also necessary to process the data entering it in real time, and I did not want to spend time on a constant long compilation.

2. Integration using a DLL.
One of the main options offered by the developers, the manual has a full description of the functions and their connection options. A great option for Windows applications, but absolutely unsuitable for use on Linux.

3. Integration using Shared objects.
The developers carefully collected the library, available in the repository, but completely forgotten in the documentation. This option was adopted for implementation, although at some points I really regretted it.

Using the example of the main function “create an environment”, the final steps for connecting this library to the program can be described by the following algorithm:

1. Using the command nm -D /usr/lib/, a list of all the functions that are in the library. A pitfall is that some functions of this library have names that do not match in the header files. For example, the CreateEnvironment function is written as __CreateEnvironment.

2. In the header files, we look for a description of a specific function and define it as a type in our program:
typedef void * (* CreateEnvironmentPtr) (void);

3. Then a variable of this type is
defined : CreateEnvironmentPtr __CreateEnvironment;

4. After the standard connection of the library using the dlopen command, the function is loaded from the library:
__CreateEnvironment = (CreateEnvironmentPtr) dlsym (dll_handle, "CreateEnvironment");

5. The pointer is defined:
void * theEnv;
with the help of which the CLIPS environment is created:
theEnv = __CreateEnvironment ();

After performing standard actions for loading the launch of an expert system, the final program fully uses the mechanism of expert systems. For example, as shown in the figure:

Thus, we launched the environment for creating expert systems (as well as the expert system itself) in an application written under Linux.

PS In the program, you can completely transfer control to the environment, using the CommandLoop command and implementing the system command line.


1. CLIPS Reference Manual. Volume II. Advanced Programming Guide.

Also popular now: