google / google/or-tools

MathOpt Gurobi backend crashes with std::bad_function_call (GRBloadenv not initialized)

Open
#5,079 7 comments 0 reactions 1 assignee Claimed by @Mizux View on GitHub
Bug Solver: Gurobi
Dominant language
C++
Stars
14.1k
Forks
2.5k
Avg merge
8h 39m
Merged PRs (30d)
72

Description

Title: MathOpt Gurobi backend crashes with std::bad_function_call (GRBloadenv not initialized)

Environment
- OR-Tools version: main (latest stable)
- Language: C++
- Gurobi versions tested: 12.0, 13.0
- Operating systems:
- openSUSE Tumbleweed
- macOS Sequoia 15

Issue
When attempting to solve a MILP model using the Gurobi backend in MathOpt, the program aborts with the following error:

terminate called after throwing an instance of 'std::bad_function_call'
what(): bad_function_call

Debugging details
While debugging, I found that the function pointer std::function GRBloadenv, defined in
ortools/third_party_solvers/gurobi_environment.h, is empty when it is called. This leads to the
std::bad_function_call exception.

This suggests that the Gurobi dynamic library was not successfully loaded. However, no explicit
error message is reported before GRBloadenv is invoked.

Expected behavior
The Gurobi backend should either:
- successfully load the Gurobi library and solve the model, or
- report a clear error indicating that the Gurobi library could not be loaded.

Actual behavior
The program aborts with std::bad_function_call.

Reproduction
1. Build OR-Tools with MathOpt enabled.
2. Configure the environment to use Gurobi.
3. Attempt to solve a MILP model using the MathOpt Gurobi backend.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.