最近使用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)
