1

my C++ project fails to build when I use the cplex/cp optimizer external libraries. I am using Cplex version 12.9 on Windows 7 with g++ compiler. I get the following error:

C:/PROGRA~1/IBM/ILOG/CPLEX_~1/concert/include/ilconcert/ilosys.h:262:10: fatal error: generic.h: No such file or directory

I have checked that my compiler/MinGw are up to date. I have also tried switching the toolchain in Clion to Visual Studio, but this results in other errors. I have been able to run the example code in cplex\examples\x64_windows_vs2017\stat_mda using Visual Studio but these example projects don't have example makefiles to compare against unfortunately. My coworker has been able to run the code on Linux with a g++ compiler in Clion.

The make file I am using is below:

cmake_minimum_required(VERSION 3.15)
project(M_MDD)

include_directories("C:/Program Files/IBM/ILOG/CPLEX_Studio129/cpoptimizer/include/")
include_directories("C:/Program Files/IBM/ILOG/CPLEX_Studio129/concert/include/")
include_directories("C:/Program Files/IBM/ILOG/CPLEX_Studio129/cplex/include/")
include_directories("C:/Program Files/boost_1_55_0")

set(CMAKE_CXX_FLAGS  "-Wall ${CMAKE_CXX_FLAGS} -DIL_STD -g -O0 -ggdb -std=c++11")

include_directories(src)

add_executable(M_MDD
        src/instances/flowshop_instances.cpp
        src/instances/flowshop_instances.hpp
        src/main.cpp
        src/mip.cpp
        src/mip.hpp
        src/util.hpp)

link_directories("C:/Program Files/IBM/ILOG/CPLEX_Studio129/cplex/lib/x64_windows_vs2017/stat_mdd/")
link_directories("C:/Program Files/IBM/ILOG/CPLEX_Studio129/concert/lib/x64_windows_vs2017/stat_mdd/")
link_directories("C:/Program Files/IBM/ILOG/CPLEX_Studio129/cpoptimizer/lib/x64_windows_vs2017/stat_mdd/")

target_link_libraries(M_MDD cplex)
target_link_libraries(M_MDD concert)
target_link_libraries(M_MDD cp)
target_link_libraries(M_MDD pthread)

Thanks!

cplextest
  • 11
  • 1

3 Answers3

1

The CPLEX detailed system requirements (click on "Version 12.9.0", "Windows", "Prerequisites") show that Visual Studio 2015-2019 are the only supported compilers on Windows. The C++ libraries in particular cannot be expected to be compatible with g++ (e.g., due to name mangling, etc.). In contrast, if you look at the system requirements on Linux, you'll see that g++ is supported there.

If we consider the error you're getting, it makes sense. In ilosys.h, line 262, we have:

#if !(defined(name2))
# if defined(ILO_MSVC) || defined(ILO_LINUX) || defined(ILO_APPLE) || defined(ILO_HP11)
#  undef name2
#  define name2(a,b)      _name2_aux(a,b)
#  define _name2_aux(a,b)      a##b
# else
#include "generic.h"
# endif
#endif

ILO_MSVC is not defined, so we hit the #include "generic.h" line.

As you mentioned, there are no makefiles for the C/C++ examples on Windows. However, the Visual Studio project files do contain everything you need to setup your project in Visual Studio. For more information on setting up your C++ projects in Visual Studio see <COSDIR>/cplex/readmeWindows.html, where <COSDIR> is the location you installed CPLEX Optimization Studio.

rkersh
  • 4,447
  • 2
  • 22
  • 31
1

I recently had the same problem, as I moved to clion for a project. This helped me a lot :

https://github.com/ampl/mp/blob/master/support/cmake/FindCPLEX.cmake https://github.com/martinWANG2014/CplexCPlusPlusDemo

Hope it helps you too,

D

Dam's
  • 11
  • 1
0

This is just an explanation to the answer by @Dam's. Even though it helped me a lot it took quite a bit of time to set it as I am new to cmake and clion, etc. This worked for Windows10. MSVC is necessary as mingw won't work.

Basically you first need to create a folder named cmake in your project directory -> Add a new file in it and name it FindCPLEX.cmake -> copy past the content of this link into that file: https://github.com/martinWANG2014/CplexCPlusPlusDemo/blob/master/cmake/FindCPLEX.cmake Do not change anything in it.

Then create a CMakeList.txt file (if it is not already there else update it) in your project directory. -> copy past the content of this link into that file: https://github.com/martinWANG2014/CplexCPlusPlusDemo/blob/master/CMakeLists.txt Here you might need to change a few things: line 5 change the name of your project: ie. set(MY_PROJECT_NAME the_name_of_your_projet). If your header and source files are in the same directory you need to create a folder for each and name it include and src respectively. Otherwise it may give you an error. OR you can just set the add_executable() at the end of the cmakelist.txt file with your project name and your src and header files manually.

Finally, if not done already, check if your settings are set as in the images of this https://github.com/martinWANG2014/CplexCPlusPlusDemo/blob/master/README.md

sos
  • 305
  • 1
  • 9