How to install gurobi in C++ Interface
AnsweredHi, i am trying to use gurobi with c++ interface. I have installed gurobi on my computer and also i have set the System variable named GRB_LICENSE_FILE but when i try to run the example mip_1c++.cpp i get the next error.
I have tried to find the solution on internet but i dont get any information how to solve it.
PD: i am using Windows10
-
Official comment
Hello! You are missing the link instruction to the compiler.
On Windows, the supported compiler is Visual C++. The "happy path" for Windows developers is to use Microsoft Visual Studio. There is a free "Community Edition" of Visual Studio that has no limitations for non-commercial use (you should read their license agreement to check your own situation).
So that makes it difficult to know what to do when you are using something else. I assume you are using MinGW. It is not supported for Gurobi, but I have tested it myself on some of the examples. So, I believe it should work for you.
If you want good build examples for MinGW, you can extract the Linux installer for Gurobi and look at the Makefile in gurobi<version>/linux64/examples. This will show you that the g++ command requires these commands:
-lgurobi_c++ -lgurobi<version>
Note that MinGW uses the Linux library naming conventions as well as the more generic approach of specifying the actual file name.
So I believe you could use this command line for Gurobi 8.1.1 (Note: I have not tested this on my own machine):
g++ mip1_c++.cpp -o mip1.exe -I c:/gurobi811/win64/include -Lc:/gurobi811/win64/lib -lgurobi_c++mt2017.lib -lgurobi81.lib
Notice that I specified the library directory with the -L switch. There is no LD_LIBRARY_PATH on Windows.
Also note: the GRB_LICENSE_FILE setting has no effect until you run the compiled program. It is not a factor when compiling or linking.
-
Hi i follow your advice and now i am using microsoft visual studio. i follow this guide to configurate gurobi https://support.gurobi.com/hc/en-us/articles/360013194392-How-do-I-configure-a-new-Gurobi-C-project-with-Microsoft-Visual-Studio-2017- but now i get this error:
it says that "cant open the file '******'
0 -
Do you solved this problem...i have the same rn.
0 -
Hello. The instructions still work. My guess is that they are difficult to follow when the default language is no English.
This error message means that Visual Studio is trying to link to a file named lib.obj. That is not what you want.
- Find Linker > General > Additional Library Directories. Additional Library Directories is the ninth (9th) item in the list.
- ... add: $(GUROBI_HOME)\lib
- Find Linker > Input > Additional Dependencies. Additional Dependencies is the first (1st) item in the list. Add this to the list of files in that box:
gurobi90.lib;gurobi_c++mdd2017.lib
0 -
A completely different solution to this problem might be to try CMake. This is entirely command-line based and may be easier to follow:
CMake: C/C++ compilation of Gurobi projects
Compiling C/C++ Projects on Windows
Cheers,
Matthias0
Please sign in to leave a comment.
Comments
5 comments