简体   繁体   English

C++:Cplex/cp 优化器 makefile 在使用 Clion 与 MinGW 和 g++ 编译器构建项目时出现问题

[英]C++: Cplex/cp optimizer makefile issues on project build using Clion with MinGW and g++ compiler

my C++ project fails to build when I use the cplex/cp optimizer external libraries.当我使用 cplex/cp 优化器外部库时,我的 C++ 项目无法构建。 I am using Cplex version 12.9 on Windows 7 with g++ compiler.我在 Windows 7 上使用 Cplex 12.9 版和 g++ 编译器。 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 C:/PROGRA~1/IBM/ILOG/CPLEX_~1/concert/include/ilconcert/ilosys.h:262:10:致命错误: generic.h : 没有这样的文件或目录

I have checked that my compiler/MinGw are up to date.我已经检查过我的编译器/MinGw 是否是最新的。 I have also tried switching the toolchain in Clion to Visual Studio, but this results in other errors.我也曾尝试将 Clion 中的工具链切换到 Visual Studio,但这会导致其他错误。 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.我已经能够使用 Visual Studio 在 cplex\examples\x64_windows_vs2017\stat_mda 中运行示例代码,但不幸的是,这些示例项目没有可供比较的示例 makefile。 My coworker has been able to run the code on Linux with a g++ compiler in Clion.我的同事已经能够在 Linux 上使用 Clion 中的 g++ 编译器运行代码。

The make file I am using is below:我正在使用的 make 文件如下:

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!谢谢!

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. CPLEX 详细的系统要求(单击“版本 12.9.0”、“Windows”、“先决条件”)显示 Visual Studio 2015-2019 是 Windows 上唯一受支持的编译器。 The C++ libraries in particular cannot be expected to be compatible with g++ (eg, due to name mangling, etc.).特别是 C++ 库不能与 g++ 兼容(例如,由于名称修改等)。 In contrast, if you look at the system requirements on Linux, you'll see that g++ is supported there.相比之下,如果您查看 Linux的系统要求,您会发现那里支持 g++。

If we consider the error you're getting, it makes sense.如果我们考虑您遇到的错误,这是有道理的。 In ilosys.h , line 262, we have:ilosys.h的第 262 行,我们有:

#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. ILO_MSVC没有定义,所以我们点击#include "generic.h"行。

As you mentioned, there are no makefiles for the C/C++ examples on Windows.正如您所提到的,Windows 上的 C/C++ 示例没有生成文件。 However, the Visual Studio project files do contain everything you need to setup your project in Visual Studio.但是,Visual Studio 项目文件确实包含在 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.有关在 Visual Studio 中设置 C++ 项目的更多信息,请参阅<COSDIR>/cplex/readmeWindows.html ,其中<COSDIR>是您安装 CPLEX Optimization Studio 的位置。

I recently had the same problem, as I moved to clion for a project.我最近遇到了同样的问题,因为我为了一个项目搬到了 clion。 This helped me a lot:这对我帮助很大:

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

Hope it helps you too,希望对你也有帮助

D D

This is just an explanation to the answer by @Dam's.这只是@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.尽管它对我有很大帮助,但由于我是 cmake 和 clion 等的新手,所以我花了很多时间来设置它。这适用于 Windows10。 MSVC is necessary as mingw won't work. MSVC 是必需的,因为 mingw 无法工作。

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.基本上,您首先需要在项目目录中创建一个名为 cmake 的文件夹 -> 在其中添加一个新文件并将其命名为 FindCPLEX.cmake -> 将此链接的内容复制到该文件中: https://github.com/martinWANG2014 /CplexCPlusPlusDemo/blob/master/cmake/FindCPLEX.cmake不要更改其中的任何内容。

Then create a CMakeList.txt file (if it is not already there else update it) in your project directory.然后在您的项目目录中创建一个 CMakeList.txt 文件(如果还没有,请更新它)。 -> 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. -> 将此链接的内容复制到该文件中: https://github.com/martinWANG2014/CplexCPlusDemo/blob/master/CMakeLists.txt在这里您可能需要更改一些内容:第 5 行更改项目的名称: IE。 set(MY_PROJECT_NAME the_name_of_your_projet) . 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.如果您的 header 和源文件位于同一目录中,您需要为每个文件创建一个文件夹,并将其分别命名为 include 和 src。 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.或者您可以在 cmakelist.txt 文件末尾手动设置 add_executable() 和您的项目名称以及您的 src 和 header 文件。

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最后,如果尚未完成,请检查您的设置是否设置为此https://github.com/martinWANG2014/CplexCPlusPlusDemo/blob/master/README.md的图像中的设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM