Creating the environment

After declaring the necessary program variables, the example continues by creating an environment:

  error = GRBloadenv(&env, "mip1.log");
  if (error || env == NULL) {
    fprintf(stderr, "Error: could not create environment\n");
    exit(1);
  }
Later attempts to create optimization models will always require an environment, so environment creation should always be the first step when using the Gurobi optimizer. The second argument to GRBloadenv() provides the name of the Gurobi log file. If the argument is an empty string or NULL, no log file will be written.

Note that environment creation may fail, so you should check the return value of the call.

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search