This is not the right question to be posting here, but is anywhere a video tutorial/ written on how to link C++ header files with Gurobi?
2 Answers
On macOS, you can find a Makefile inside /Library/gurobi950/macos_universal2/examples/build
to compile all examples. Open the Terminal.app and enter the following:
# change the directory
cd /Library/gurobi950/macos_universal2/examples/build
# compile and run all c++ examples
make run_c++
This will compile and run all c++ examples. If you want to compile a specific c++ example, you only need to include the gurobi header and link to the gurobi library. Let's take mip1_c++.cpp
as an example and let's take the clang++
compiler:
# define bash variable for Gurobi's path
GUROBI_HOME="/Library/gurobi950/macos_universal2/"
# change the directory
cd $GUROBI_HOME/examples/c++
# Compile the program
clang++ mip1_c++.cpp -I${GUROBI_HOME}/include/ -L${GUROBI_HOME}/lib -lgurobi_c++ -lgurobi95 -o mip1_c++
Then you can execute the program inside the Terminal.app by ./mip1_c++
. Last but not least, if you're working with C++, it's highly recommended to make yourself familiar with Makefile-Generator tools like CMake.
-
$\begingroup$ Thanks a ton, Joni! Indeed, I am trying to figure out C++ with optimisation softwares. But, I must say it is quite a maze. Would you know of any resources to aid me? $\endgroup$– IshaanFeb 23, 2022 at 11:28
There is a dedicated section about C++ programming with Gurobi in the official documentation.
There is also a CMake example in the Gurobi Knowledge Base.
-
$\begingroup$ Thanks, Matt. Apologise for bother here as well as on Gurobi thread. I was struggling, a bit. $\endgroup$– IshaanFeb 23, 2022 at 18:00
target_link_libraries(my_package PUBLIC GUROBI::GUROBI)
$\endgroup$