How to: compile C++ with Gurobi in Linux

In order to compile your C++ project with Gurobi, you first need to create the appropriate libgurobi_c++.a compatible with your g++ version. To do so, access the following directory and compile it:

cd [GRB_path]/linux64/src/build
make
The file is now created, so copy it to the lib folder:
cp libgurobi_c++.a ../../lib/
Now you can create your makefile. For example:
CCC = g++ 
FLAGS = -g -Wall -Wextra 
GRBPATH = /[full path to]/gurobi752/ 

exec: code.cpp 
     $(CCC) $(FLAGS) code.cpp -o exec -I$(GRBPATH)/linux64/include -L$(GRBPATH)/linux64/lib -lgurobi_c++ -lgurobi75 

clean: 
     rm -f code *.o *~

You might need to change spaces to tabs in the above makefile.

This was useful? Buy me a cup of coffee to help me keep this website running!