CMake is a platform-independent build system to compile C/C++ code. To link Gurobi to your project, you can extend the template files attached to this article, which consists of the following:
-
FindGUROBI.cmaketo determine the necessary include and linker commands -
CMakeLists.txtto specify how your code needs to be built
Note: This template uses mip1_c++.cpp from the Gurobi C++ examples directory and expects this file to be in the root directory of the project (the same directory as the main CMakeLists.txt).
Build a C/C++ project on Windows
cmake -B build
cmake --build buildThe first command sets up a new directory build to contain all the build files, while the second actually performs the compilation and creates the executable. To specify whether to create a debug or production build, please append the --config flag to the last command, e.g.:
cmake --build build --config Releaseor
cmake --build build --config DebugThis will also determine the location of the resulting executable: build\Release\ or build\Debug\.
Build a C/C++ project on Linux/macOS
cmake -B build
cmake --build buildTo build a pure C project, specify -DCXX=off in the first step. These commands will create a new subdirectory named build, where the compiled files can be found. In contrast to Windows, the configuration or build type is already defined in the configuration step in the first command:
cmake -B build -DCMAKE_BUILD_TYPE=Releaseor
cmake -B build -DCMAKE_BUILD_TYPE=Debug
Further information
- How do I resolve "undefined reference" errors while linking Gurobi in C++?
- How do I build C/C++ projects on Windows?