Cannot find license when using c++/cmake
AnsweredHi,
I'm trying to build Cmake project according https://support.gurobi.com/hc/en-us/articles/360039499751-How-do-I-use-CMake-to-build-Gurobi-C-C-projects- .
Now, it has been able to compile. But when it is executed, it throws GRBException like
No Gurobi license, or license not started or set
I did not modify FindGUROBI.cmake and CMakeLists.txt, but i simplified mip1_c++.cpp to show the problem.
#include <iostream>
#include <gurobi_c++.h>
int main() {
GRBEnv env = GRBEnv(true);
env.set("LogFile", "./test.log");
try {
GRBModel model = GRBModel(env);
}catch(GRBException e) {
std::cout<<e.getMessage()<<std::endl;
}
return 0;
}
If I call Gurobi by terminal command, everthing looks well.
$ gurobi_cl
Set parameter Username
Set parameter LogFile to value "gurobi.log"
Academic license - for non-commercial use only - expires 2024-04-18
Using license file /home/xia/gurobi.lic
Usage: gurobi_cl [--command]* [param=value]* filename
Type 'gurobi_cl --help' for more information.
My Gurobi path is
/opt/gurobi1001/linux64
I set environment variable in /etc/profile
# >>> gurobi init >>>
export GUROBI_HOME="/opt/gurobi1001/linux64"
export PATH="$GUROBI_HOME/bin"${PATH:+:$PATH}
export C_INCLUDE_PATH="$GUROBI_HOME/include"${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}
export CPLUS_INCLUDE_PATH="$GUROBI_HOME/include"${CPLUS_INCLUDE_PATH:+:$CPLUS_INCLUDE_PATH}
export LD_LIBRARY_PATH="$GUROBI_HOME/lib"${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
# <<< gurobi init <<<
My license path is
/home/xia/gurobi.lic
-
Hi Zixun,
The error comes from this line:
GRBEnv env = GRBEnv(true);
You are instructing Gurobi to create an empty environment (GRBEnv()) by specifying the optional parameter \(\texttt{empty=true}\). This is fine as long as you also start the environment via GRBEnv::start(). Using an empty env is intended to be used for specifying other license parameters to extend or replace what is written in the license file.
For your license, it is sufficient to call the env constructor without the bool parameter to immediately start the environment. So, you just need to remove the \(\texttt{true}\) from the constructor to fix your code.
Cheers,
Matthias1
Please sign in to leave a comment.
Comments
1 comment