1
$\begingroup$

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?

$\endgroup$
6
  • $\begingroup$ Have you checked the tutorials by Gurobi? If you're using Windows, support.gurobi.com/hc/en-us/articles/… $\endgroup$ Feb 22, 2022 at 1:50
  • $\begingroup$ I don't know whether this exists, but I do think that the question is in the scope of the website $\endgroup$ Feb 22, 2022 at 19:10
  • $\begingroup$ I've found this article really useful as depending on the compiler, you may need to rebuild the Gurobi libraries: support.gurobi.com/hc/en-us/articles/… Can you run the standard C++ examples (provided under the folder where you installed Gurobi)? $\endgroup$ Feb 22, 2022 at 19:28
  • $\begingroup$ Also, if you're using CMake, you can use this to find the header files and libraries: gist.github.com/torressa/27efc65710a6d5948fbf649a419af300 Then you can use it like any other CMake package target_link_libraries(my_package PUBLIC GUROBI::GUROBI) $\endgroup$ Feb 22, 2022 at 19:45
  • $\begingroup$ Thanks @NaraBegnini and @DavidTorres! I am running it on MacOS. I am unable to run the examples provided under the folder where Gurobi is installed. $\endgroup$
    – Ishaan
    Feb 23, 2022 at 10:25

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
1
  • $\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$
    – Ishaan
    Feb 23, 2022 at 11:28
6
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Thanks, Matt. Apologise for bother here as well as on Gurobi thread. I was struggling, a bit. $\endgroup$
    – Ishaan
    Feb 23, 2022 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.