ILOG CPLEX 11.0 User's Manual > Programming Considerations > Licensing an Application > Examples > CPXputenv Routine for C and C++ Users

This example illustrates the routine CPXputenv to open the CPLEX environment.

char *inststr = NULL;
char *envstr  = NULL;

/* Initialize the CPLEX environment */

envstr = (char *) malloc (256);
if ( envstr == NULL ) {
   fprintf (stderr, "Memory allocation for CPXputenv failed.\n");
   status = FAIL;
   goto TERMINATE;
}
else {
   inststr = (char *)  getenv("MYAPP_HOME");
   if ( inststr == NULL ) {
      fprintf (stderr, "Unable to find installation directory.\n");
      status = FAIL;
      goto TERMINATE;
   }
   strcpy (envstr, "ILOG_LICENSE_FILE=");
   strcat (envstr, inststr);
   strcat (envstr, "\\license\\access.ilm");
   CPXputenv (envstr);
}

env = CPXopenCPLEX (&status);

.

Notes
This example assumes a Microsoft Windows file directory structure that requires an additional backslash when specifying the path of the file containing the key. It also assumes that the application uses an environment variable called MYAPP_HOME to identify the directory in which it was installed.

The string argument to CPXputenv must remain active throughout the time ILOG CPLEX is active; the best way to do this is to malloc the string.