CMake is a platform-independent build system to compile C/C++ code. To link Gurobi into your project you can extend the template attached to this article, which consists of:
- FindGUROBI.cmake to determine the necessary include and linker commands
- CMakeLists.txt to specify how your code needs to be built
Build a C/C++ project on Windows
cmake -H. -Bbuild
cmake --build build
The 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 Release
or
cmake --build build --config Debug
This will also determine the location of the resulting executable: build\Release\ or build\Debug\.
Build a C/C++ project on Linux/macOS
cmake -H. -Bbuild
cmake --build build
To build a pure C project, you can 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 -H. -Bbuild -DCMAKE_BUILD_TYPE=Release
or
cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug
Note: This template uses mip1_c++.cpp from the Gurobi C++ examples directory.
Further information
- How do I resolve "undefined reference" errors while linking Gurobi in C++?
- How do I build C/C++ projects on Windows?