0

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++.

mdslt
  • 155
  • 1
  • 10
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – ChrisMM Oct 24 '22 at 12:50
  • You've only added the `include_directory`, you need to actually link the library. – ChrisMM Oct 24 '22 at 12:50
  • https://support.gurobi.com/hc/en-us/articles/360039499751-How-do-I-use-CMake-to-build-Gurobi-C-C-projects- – Mat Oct 24 '22 at 12:51
  • @Mat, the link you posted was not helpful (if I have not missed anything). I included two files provided in this link in my project directory and replicated the commands in my CLion's terminal. However, they did not work. I'll update my post with this information. – mdslt Oct 24 '22 at 12:56
  • Your CMakeList file is lacking pretty much everything that is in the one they provide. – Mat Oct 24 '22 at 12:59
  • @ChrisMM, as per your suggestion, I included `link_directories(C:/gurobi952/win64/lib)` in the `CMakeLists.txt` as well. However, the same error persists! – mdslt Oct 24 '22 at 13:29
  • `link_directories` just adds a search path, it doesn't link anything. You probably want `target_link_libraries`, and you need to specify the library. – ChrisMM Oct 24 '22 at 13:34

0 Answers0