c++ - 使用 MINGW 并链接 CPLEX 库从 Linux 编译 Windows 可执行文件

标签 c++ linux compilation mingw cplex

这项工作的重点是防止我双启动窗口,必须在同一系统中安装 CPLEX 两次(存储空间非常有限)并且能够从我的主操作系统编译所需的跨平台可执行文件debian Linux.

因此我使用的是 mingw64,我的编译脚本如下所示:

#!/bin/sh
#COMPILATION FLAGS
FLAGS='-DIL_STD -DILOUSEMT -D_REENTRANT'
EXTRA='-std=c++11 -static -static-libgcc -static-libstdc++'
#INCLUDES
OPL_INCL='-I/opt/ibm/ILOG/CPLEX_Studio128/opl/include'
CPL_INCL='-I/opt/ibm/ILOG/CPLEX_Studio128/cplex/include'
CON_INCL='-I/opt/ibm/ILOG/CPLEX_Studio128/concert/include'
#LINKER
OPL_LIB='-L/opt/ibm/ILOG/CPLEX_Studio128/opl/lib/x64_windows_vs2017/stat_mda'
CPL_LIB='-L/opt/ibm/ILOG/CPLEX_Studio128/cplex/lib/x64_windows_vs2017/stat_mda'
CON_LIB='-L/opt/ibm/ILOG/CPLEX_Studio128/concert/lib/x64_windows_vs2017/stat_mda'

#echo $FLAGS
/usr/bin/x86_64-w64-mingw32-g++ $FLAGS $OPL_INCL $EXTRA main.cpp $OPL_LIB $CON_LIB $CPL_LIB -lcplex -lm -lpthread
#g++ -std=c++11 $FLAGS $OPL_INCL main.cpp $OPL_LIB $CON_LIB $CPL_LIB -lcplex -lm -lpthread

我所做的是,我从另一个 Windows 安装中复制了 Windows 版本的库文件,现在我正在尝试使用全局(我想)包含文件编译我的代码,但使用 Windows 版本(.lib ) 必要的 cplex 库。

我原以为梦魇会是链接,但令我惊讶的是,我什至没有设法到达那里。 Mingw 编译器由于缺少 generic.h 文件而中止编译(根据我的一些搜索,它应该与内核或其他东西有关)

In file included from /opt/ibm/ILOG/CPLEX_Studio128/opl/include/ilconcert/iloenv.h:21:0,
                 from /opt/ibm/ILOG/CPLEX_Studio128/opl/include/ilconcert/iloalg.h:21,
                 from /opt/ibm/ILOG/CPLEX_Studio128/opl/include/ilconcert/ilomodel.h:21,
                 from /opt/ibm/ILOG/CPLEX_Studio128/opl/include/ilcplex/ilocplex.h:27,
                 from /opt/ibm/ILOG/CPLEX_Studio128/opl/include/ilopl/iloopl.h:23,
                 from main.cpp:3:
/opt/ibm/ILOG/CPLEX_Studio128/opl/include/ilconcert/ilosys.h:262:21: fatal error: generic.h: No such file or directory
 #include "generic.h"
                     ^
compilation terminated.

我还尝试使用 g++ 进行编译测试,这个错误很快就被绕过了,正如预期的那样,新错误与链接 cplex 库有关:/usr/bin/ld:找不到 -lcplex,它可能丢失了,因为我没有包含 linux 库文件夹。

我是否有希望这样做,或者这首先是不可能的?

PS:我有一段更简单的代码,其中我正在做完全相同的事情(没有 CPLEX),编译工作就像一个魅力。所以我想这个问题也应该与 CPLEX 相关。

最佳答案

简短的回答是否定的;您可能没有任何希望让它发挥作用。

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 没有定义,这就是包含 generic.h 的原因。如果我们转到第 11 行的 ilosys.h,我们会看到:

#if defined(_MSC_VER)
# undef  _Windows
# define _Windows
# undef  _WINDOWS
# define _WINDOWS
# undef  ILO_WINDOWS
# define ILO_WINDOWS
# undef  ILO_MSVC
# define ILO_MSVC
#include <stddef.h>
# if defined(_WIN64)
#  undef  ILO64
#  define ILO64
#  undef  ILO_WIN64
#  define ILO_WIN64
# else
#  undef  ILO_WIN32
#  define ILO_WIN32
# endif
//# if defined(ILO_MSVC8)
//#  undef _WIN32_WINNT
//#  define _WIN32_WINNT 0x0400
//# endif
#endif

因此,只有在定义了 _MSC_VER 时,才会定义 ILO_MSVC。并且,_MSC_VER 仅在您安装了 Microsoft Visual C++ 编译器时定义(例如,参见 here)。

最后,如果您查看 detailed system requirements对于 CPLEX 和 Windows,很明显需要 Microsoft Visual Studio 2015 或 2017。

关于c++ - 使用 MINGW 并链接 CPLEX 库从 Linux 编译 Windows 可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50493419/

相关文章:

c - closedir() 后无效的 free()

linux - Linux 中 "./configure"的各种选项/参数是什么

c++ - 如何确定 cdt eclipse 中 c++ 项目的正确链接器顺序?

c++ - 如何克隆多个继承对象?

linux - docker 可以在 Linux 容器中运行吗?

compilation - Gem5编译过程中的警告

assembly - 扩展编译器以获得自己的汇编输出

java - 这些构造之间有什么区别,以至于无法编译?

c++ - 如何仅在本地 header 上运行预处理器?

c++ - 将类型 T 的多态包装器转换为类型 U?