我需要在项目中使用R包Rglpk,需要修改包——特别是我需要在界面中添加一个时间限制控制参数选项(它是GLPK v4.5.2本身的一个选项,但是Rglpk 0.5- 2 不支持此参数)。这将允许 R 调用 GLPK 并限制用户指定的搜索时间(即搜索时间 <= t)。
我已经修改了 Rglpk 代码,并在 Mac OS X v10.9.2 上成功编译了该包,并验证它按预期工作。我的项目需要在 Windows 上运行,但我无法在 Windows 上编译修改后的 Rglpk 包,或者就此而言未修改的包 (Rglpk 0.5-2)。我已经尝试将原始包上传到 Win Builder ( http://win-builder.r-project.org/ ),但我收到了同样的错误。
以下是我在 Windows 7(我的机器)上所做的总结:
(1) 从http://cran.r-project.org/web/packages/Rglpk/index.html下载 Rglpk 0.5-2 包源 (2) 将文件解压缩到一个目录。所有代码都在一个名为 Rglpk 的目录中。(3) 启动 RStudio v0.98.490。我已经安装了devtools v1.4.1,安装了Rtools v3.1,还有R v3.0.2 (4)打开一个新项目,选择(2)中提到的Rglpk目录。(5) 在“Build”菜单下,选择“Build and Reload”。这样做的结果是包编译并被加载:
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (Rglpk)
(6) 在“Build”菜单下,选择“Check Package”。结果是安装失败。日志文件如下所示。
我试图编译另一个包含 C 代码的包,但也无法编译它。我尝试编译的包是 devtools v1.5 在这种情况下返回的错误是“LoadLibrary 失败:%1 不是有效的 Win32 应用程序。”
有没有人有在 Windows 上编译包含 C 代码的 R 包的经验?我已经能够编译只涉及 R 代码的包,但 C 代码似乎很麻烦。
任何帮助,将不胜感激。
日志文件
* using R version 3.0.2 (2013-09-25)
* using platform: x86_64-w64-mingw32 (64-bit)
* using session charset: ISO8859-1
* checking for file 'Rglpk/DESCRIPTION' ... OK
* this is package 'Rglpk' version '0.5-2'
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... NOTE
Found the following apparent object files/libraries:
src/GLPK/alloc.o src/GLPK/amd/amd_1.o src/GLPK/amd/amd_2.o
src/GLPK/amd/amd_aat.o src/GLPK/amd/amd_control.o
src/GLPK/amd/amd_defaults.o src/GLPK/amd/amd_dump.o
src/GLPK/amd/amd_info.o src/GLPK/amd/amd_order.o
src/GLPK/amd/amd_post_tree.o src/GLPK/amd/amd_postorder.o
src/GLPK/amd/amd_preprocess.o src/GLPK/amd/amd_valid.o
src/GLPK/bignum.o src/GLPK/cfg.o src/GLPK/cfg1.o
src/GLPK/colamd/colamd.o src/GLPK/dmp.o src/GLPK/env.o
src/GLPK/error.o src/GLPK/ffalg.o src/GLPK/fhv.o src/GLPK/fhvint.o
src/GLPK/glpapi01.o src/GLPK/glpapi02.o src/GLPK/glpapi03.o
src/GLPK/glpapi04.o src/GLPK/glpapi05.o src/GLPK/glpapi06.o
src/GLPK/glpapi07.o src/GLPK/glpapi08.o src/GLPK/glpapi09.o
src/GLPK/glpapi10.o src/GLPK/glpapi11.o src/GLPK/glpapi12.o
..... (more lines are here, I have removed them for brevity)
src/GLPK/triang.o src/GLPK/wclique.o src/GLPK/wclique1.o
src/GLPK/zlib/adler32.o src/GLPK/zlib/compress.o
src/GLPK/zlib/crc32.o src/GLPK/zlib/deflate.o src/GLPK/zlib/gzclose.o
src/GLPK/zlib/gzlib.o src/GLPK/zlib/gzread.o src/GLPK/zlib/gzwrite.o
src/GLPK/zlib/inffast.o src/GLPK/zlib/inflate.o
src/GLPK/zlib/inftrees.o src/GLPK/zlib/trees.o
src/GLPK/zlib/uncompr.o src/GLPK/zlib/zio.o src/GLPK/zlib/zutil.o
Object files/libraries should not be included in a source package.
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking whether package 'Rglpk' can be installed ... ERROR
Installation failed.
The contents of the 00install.out file are:
* installing *source* package 'Rglpk' ...
** libs
*** arch - i386
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_initialize.c -o Rglpk_initialize.o
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_read_file.c -o Rglpk_read_file.o
Rglpk_read_file.c: In function 'Rglpk_read_file':
Rglpk_read_file.c:84:6: warning: 'status' may be used uninitialized in this function [-Wuninitialized]
Rglpk_read_file.c: In function 'Rglpk_retrieve_MP_from_file':
Rglpk_read_file.c:192:6: warning: 'status' may be used uninitialized in this function [-Wuninitialized]
gcc -m32 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -IGLPK -IGLPK/amd -IGLPK/colamd -IGLPK/minisat -IGLPK/proxy -IGLPK/zlib -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c Rglpk_solve.c -o Rglpk_solve.o
Rglpk_solve.c: In function 'R_glp_solve':
Rglpk_solve.c:25:10: warning: variable 'kl' set but not used [-Wunused-but-set-variable]
gcc -m32 -shared -s -static-libgcc -o Rglpk.dll tmp.def Rglpk_initialize.o Rglpk_read_file.o Rglpk_solve.o GLPK/libglpk.a -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-30~1.2/bin/i386 -lR
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpmpl04.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(error.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpmpl03.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(alloc.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `GLPK/libglpk.a(glpenv07.o)' is incompatible with i386 output
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe:
.....
Error: 64-bit reloc in dll
Error: 64-bit reloc in dll
Error: 64-bit reloc in dll
.....
Rglpk_initialize.o:Rglpk_initialize.c:(.text+0x33): undefined reference to `glp_term_hook'
Rglpk_initialize.o:Rglpk_initialize.c:(.text+0x44): undefined reference to `glp_version'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x10): undefined reference to `glp_delete_prob'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x4f): undefined reference to `glp_term_out'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x60): undefined reference to `glp_delete_prob'
Rglpk_read_file.o:Rglpk_read_file.c:(.text+0x65): undefined reference to `glp_create_prob'
.....
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4326): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4d39): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4dc5): undefined reference to `strcpy'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4e05): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x4e16): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x502e): undefined reference to `floor'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x50e2): undefined reference to `sprintf'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x5111): undefined reference to `sprintf'
.....
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x990): undefined reference to `exp'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0x9e0): undefined reference to `log'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xa30): undefined reference to `log10'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xaee): undefined reference to `sin'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb4e): undefined reference to `cos'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb65): undefined reference to `atan'
GLPK/libglpk.a(glpmpl03.o):glpmpl03.c:(.text+0xb79): undefined reference to `atan2'
.....
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ec0): undefined reference to `memcpy'
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ed5): undefined reference to `memcpy'
GLPK/libglpk.a(deflate.o):deflate.c:(.text+0x2ee7): undefined reference to `memcpy'
GLPK/libglpk.a(zutil.o):zutil.c:(.text+0x47): undefined reference to `malloc'
GLPK/libglpk.a(zutil.o):zutil.c:(.text+0x54): undefined reference to `free'
collect2: ld returned 1 exit status
ERROR: compilation failed for package 'Rglpk'