Sets a log routine.

void put_logfunc(lprec *lp, logfunc newlog, void *loghandle);

Return Value

put_logfunc has no return value.



Pointer to previously created lp model. See return value of make_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI


The log routine.

typedef void (__WINAPI logfunc)(lprec *lp, void *userhandle, char *buf);
Note the __WINAPI attribute. This is important under Windows. It ensures __stdcall calling convention which is required.


A parameter that will be provided to the log routine.


The put_logfunc function sets a log routine.
When set, the log routine is called when lp_solve has someting to report. The return value of this routine should be 0. The log routine can be cleared by specifying NULL as log routine.
This function is called at the same time as something is written to file set via set_outputstream, set_outputfile.


#include <stdio.h>
#include <stdlib.h>
#include "lp_lib.h"

void __WINAPI logfunction(lprec *lp, void *userhandle, char *buf)

 /* do something with buf (the message) */


int main(void)
  lprec *lp;

  /* Create a new LP model */
  lp = make_lp(0, 0);
  if(lp == NULL) {
    fprintf(stderr, "Unable to create new LP model\n");

  put_logfunc(lp, logfunction, NULL);
  set_verbose(lp, FULL);

  del_column(lp, 1); /* Will generate an error because column 1 does not exist */
                     /* Note that del_column returns FALSE (0) to indicate an error */

lp_solve API reference

See Also make_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, put_abortfunc