最近使用R进行生物信息多组学分析,需要用到cplex,安装走了不少弯路,记录这个过程。
首先需要安装cplex;我的安装如下,
1.下载地址:cplex_studio1263.win-x86-64百度网盘:https://pan.baidu.com/s/1_d3rQIw8Uzv__btewMFlOA
2.cplex安装好之后,需要配置环境变量。
3.从官网下载cplexAPI_1.3.3.tar.gz包,如果按照其默认安装,出错,找不到文件夹,原因是,获取不到刚才安装的cplex_studio1263的路径,这就需要对其进行设置绝对路径。
我的设置如下:参考github的安装方式:https://github.com/bayesteecal/cplexAPI/blob/master/inst/INSTALL
里面src中的Makevars.win文件,指定真正的文件路径
PKG_CPPFLAGS=-g -D_R_=1 -DUSE_R=1 -I"C:\soft_install\cplex\cplex\include"
PKG_LIBS=-L"C:\soft_install\cplex\cplex\lib" -lm -lcplex1236
其中lcplex1236是你安装cplex_studio1263对应的版本号。
但build之后出现如下错误。
C:\Users\openstack> R CMD INSTALL --build --no-multiarch .\cplexAPI_1.3.3.tar.gz
* installing to library ‘C:/Users/openstack/Documents/R/win-library/4.1‘
* installing *source* package ‘cplexAPI‘ ...
** package ‘cplexAPI‘ successfully unpacked and MD5 sums checked
** using staged installation
** libs
"C:/soft_install/rtools40/mingw64/bin/"gcc -I"C:/soft_install/R/R-4.1.1/include
" -DNDEBUG -g -D_R_=1 -DUSE_R=1 -I"C:\soft_install\cplex\cplex\include"
-O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c cplexAPI.c -o cplex
API.o
C:\soft_install\cplex\cplex\include/ilcplex/cpxconst.h:249:62: error: expected ‘
)‘ before ‘deprecated‘
# define CPXDEPRECATEDAPI(version) __declspec(dllimport deprecated)
^~~~~~~~~~
C:\soft_install\cplex\cplex\include/ilcplex/cplex.h:35:1: note: in expansion of
macro ‘CPXDEPRECATEDAPI‘
CPXDEPRECATEDAPI(12060200)
^~~~~~~~~~~~~~~~
C:\soft_install\cplex\cplex\include/ilcplex/cpxconst.h:249:41: error: expected i
dentifier or ‘(‘ before ‘)‘ token
# define CPXDEPRECATEDAPI(version) __declspec(dllimport deprecated)
^~~~~~~~~~
C:\soft_install\cplex\cplex\include/ilcplex/cplex.h:35:1: note: in expansion of
macro ‘CPXDEPRECATEDAPI‘
CPXDEPRECATEDAPI(12060200)
解决方法需要在Makevars.win第一句后面加入这句话:-DBUILD_CPXSTATIC
最终Makevars.win配置文件如下:
PKG_CPPFLAGS=-g -D_R_=1 -DUSE_R=1 -I"C:\soft_install\cplex\cplex\include" -DBUILD_CPXSTATIC
PKG_LIBS=-L"C:\soft_install\cplex\cplex\bin\x64_win64" -lm -lcplex1263
在build ;install,
R CMD build --no-build-vignettes --no-manual --md5 C:\Users\{your name here}\Desktop\cplexAPI
R CMD INSTALL --build --no-multiarch .\cplexAPI_1.3.3.tar.gz
最后成功提示如下
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* MD5 sums
packaged installation of ‘cplexAPI‘ as cplexAPI_1.3.3.zip
* DONE (cplexAPI)