Configure Gurobi C++ project with Microsoft Visual Studio 2022
AnsweredHello,
I'm using the VS 2022, and I have some trouble compiling the GUROBI C++ project, which I believe is related to the toolset version 143 of VS2022 is perhaps not supported by GUORBI. Do I have to replace it with VS 2019? Can I do something to avoid the reinstalling by, for example, installing the MSVC toolset version 142 via VS 2022?
I really appreciate any help you can provide.
-
Hi,
Since you did not provide any error message I have to guess that what you mean is an error similar to
C:\gurobi950\win64\examples\c++\workforce2_c++.cpp : fatal error C1041: cannot open program database 'C:\gurobi950\win64\examples\build\projects2019\Release\vc142.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
which occurs when building the solution using the solution file \(\texttt{C++_examples_2019.sln}\) using Visual Studio 2019 (or 2022). This error occurs, because multiple projects, e.g., batchmode_c++ and workforce1_c++, are compiled at the same time and both use the \(\texttt{vc142.pdb}\) database. To avoid this issue, you should build the projects one by one by right-clicking on, e.g., batchmode_c++, in the Solution Explorer and selecting "Build". This will build only a single project and does not throw the above error. This should also work for Visual Studio 2022 Community Edition.
Please note that while Gurobi should work fine with Visual Studio 2022, it is not officially supported yet.
Best regards,
Jaromił0 -
Hello Jaromił,
Thanks for your quick response! I'm actually trying to build a project using CMake. And the following is my FindGUROBI.cmake file:
find_path(GUROBI_INCLUDE_DIRS
NAMES gurobi_c++.h
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES include)
find_library(GUROBI_LIBRARY
NAMES gurobi gurobi90 gurobi91 gurobi95
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
if(MSVC)
# determine Visual Studio year
if(MSVC_TOOLSET_VERSION EQUAL 142)
set(MSVC_YEAR "2019")
elseif(MSVC_TOOLSET_VERSION EQUAL 141)
set(MSVC_YEAR "2017")
elseif(MSVC_TOOLSET_VERSION EQUAL 140)
set(MSVC_YEAR "2015")
endif()
if(MT)
set(M_FLAG "mt")
else()
set(M_FLAG "md")
endif()
find_library(GUROBI_CXX_LIBRARY
NAMES gurobi_c++${M_FLAG}${MSVC_YEAR}
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
find_library(GUROBI_CXX_DEBUG_LIBRARY
NAMES gurobi_c++${M_FLAG}d${MSVC_YEAR}
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
else()
find_library(GUROBI_CXX_LIBRARY
NAMES gurobi_c++
HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
PATH_SUFFIXES lib)
set(GUROBI_CXX_DEBUG_LIBRARY ${GUROBI_CXX_LIBRARY})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_LIBRARY GUROBI_INCLUDE_DIRS)And I got the error:
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_DEBUG_LIBRARY
GUROBI_CXX_LIBRARYI suspect it's because the MSVC_TOOLSET_VERSION is 143 in VS 2022, so the two libraries can not be successfully found. In this case, shall I default any PC with MSVC_TOOLSET_VERSION newer than 142 to use the lib built with MSVC_YEAR = 2019, for example gurobi_c++md2019.lib and gurobi_c++mdd2019.lib?
Thanks a lot!
0 -
Thank you for the clarification.
I suspect it's because the MSVC_TOOLSET_VERSION is 143 in VS 2022, so the two libraries can not be successfully found. In this case, shall I default any PC with MSVC_TOOLSET_VERSION newer than 142 to use the lib built with MSVC_YEAR = 2019, for example gurobi_c++md2019.lib and gurobi_c++mdd2019.lib?
Yes, there are currently no libraries built for the 2022 version. I tested the gurobi_c++ 2019 libraries with MSVC2022 Community Edition and it compiled correctly (except for a sprint_f warning due to an updated compiler version in MSVC2022). So using the 2019 Gurobi C++ libraries should work in this case
[...]
if(MSVC_TOOLSET_VERSION GREATER_EQUAL 142)
set(MSVC_YEAR "2019")
[...]Best regards,
Jaromił0 -
Thanks for your informative suggestions! That helps. -Qing
0
Please sign in to leave a comment.
Comments
4 comments