I am trying to install gurobi 952 on windows 10 for c++
(CLion). I have an active gurobi license (it works with Java and Python), however, I cannot run it in c++
. I looked for solutions on the internet and found several topics, but none with a solution, especially for windows users.
I have created the CMakeLists.txt
as follows:
cmake_minimum_required(VERSION 3.13)
project(CHEO)
set(CMAKE_CXX_STANDARD 20)
include_directories(C:/gurobi952/win64/include)
add_executable(CHEO main.cpp)
Also, I am initializing the gurobi main file as follows:
#include "iostream"
#include "gurobi_c++.h"
using namespace std;
int
main(int argc,
char *argv[])
{
try {
cout << "Hello" << endl;
// Create an environment
GRBEnv env = GRBEnv(true);
} catch(...) {
cout << "Exception during optimization" << endl;
}
return 0;
}
Nevertheless, I encounter an error saying:
[1/2] Building CXX object CMakeFiles/CHEO.dir/main.cpp.obj
[2/2] Linking CXX executable CHEO.exe
FAILED: CHEO.exe
cmd.exe /C "cd . && C:\PROGRA~1\JETBRA~1\CLION2~1.4\bin\mingw\bin\G__~1.EXE -g CMakeFiles/CHEO.dir/main.cpp.obj -o CHEO.exe -Wl,--out-implib,libCHEO.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Program Files\JetBrains\CLion 2022.2.4\bin\mingw\bin/ld.exe: CMakeFiles/CHEO.dir/main.cpp.obj:C:/Users/USERNAME/CLionProjects/CHEO/main.cpp:12: undefined reference to `GRBEnv::GRBEnv(bool)'
C:\Program Files\JetBrains\CLion 2022.2.4\bin\mingw\bin/ld.exe: CMakeFiles/CHEO.dir/main.cpp.obj: in function `main':
C:/Users/USERNAME/CLionProjects/CHEO/main.cpp:48: undefined reference to `GRBEnv::~GRBEnv()'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
In addition, I have tried the solution provided here (gurobi's support website). However, once I included the suggested files in the directory of my project (CMakeLists.txt
and FindGUROBI.cmake
), I fill face the following error during the compilation of the CMakeLists.txt
file:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GUROBI_CXX_LIBRARY
linked by target "gurobi-template" in directory C:/Users/USERNAME/CLionProjects/CHEO
linked by target "gurobi-template" in directory C:/Users/USERNAME/CLionProjects/CHEO
What could be a solution to this problem for a windows user? Thanks for your patience in advance as I am new to c++
.