1. Calling CPLEX from C on a Unix server


Calling CPLEX from C on a Unix server

Question:

How do I call CPLEX libraries from my own program written in C on an ITS Unix server?

Answer:

Unix installations of the CPLEX libraries are installed on servers that are running on a Solaris 8 operating system. If you do not yet have ITS unix service validation you will need to acquire an ITS-issued account (IF or departmental) that has been validated for UTS service.

You can compile a linear programming example, e.g., the file lpex2.c which comes with the CPLEX libraries distribution, in your account’s home directory and run the executable at your shell prompt as a learning exercise and as a template for constructing your own program.

For this purpose the following steps can be taken, where it is assumed that you are in your account’s home directory and that you are using csh as your shell:

1. Set up the Unix environment for statistical and mathematical applications using the perl script “appuser”. At the shell prompt, (usually “%” for csh) you should execute the command

% eval `/usr/local/etc/appuser`

being careful that the script location is contained in backquotes.

2. Make a local copy of the lpex2.c file. It can be copied from the cplex area on ITS Unix servers using the command

% cp /usr/local/cplex/cplex81/examples/src/lpex2.c .

The permissions should be set at an adequate level, e.g.,

% chmod 644 lpex2.c

3. Make a local copy of the Makefile for the examples. It can be copied from the
cplex area on ITS Unix servers using the command

% cp /usr/local/cplex/cplex81/examples/ultrasparc_5_5.0/static_pic_mt/Makefile .

This file should also have adequate permissions, which can be assured with the command

% chmod 644 Makefile

4. Use the “make” command to compile and link executables. The path for this
command may not be in your PATH variable, so you might need to use the absolute
path from root. You could also make an alias, or add /usr/ccs/bin to your PATH variable.

% /usr/ccs/bin/make lpex2

5. You should now have the executable lpex2 in your home directory. To assure that
you have execute permission, use the command

% chmod 755 lpex2

6. Now you can run the compiled program by typing its name at the shell prompt. This lpex2 example requires the name of a file from which to read data, and a specification of 
the optimization method to be used. You can check the executable using the data file
/usr/local/cplex/cplex81/examples/data/example.mps and the default optimization
procedure, designated by “o”, with the command

% lpex2 /usr/local/cplex/cplex81/examples/data/example.mps o

Back to top