【问题标题】:Error compiling Rglpk on Windows在 Windows 上编译 Rglpk 时出错
【发布时间】:2014-05-01 20:07:37
【问题描述】:

我需要在一个项目中使用R包Rglpk,需要修改包——特别是我需要在界面中添加一个时间限制控制参数选项(它是GLPK v4.5.2本身的一个选项,但是Rglpk 0.5-2 不支持此参数)。这将允许 R 调用 GLPK 并限制用户指定的搜索时间(即搜索时间

我已经修改了 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) 在“构建”菜单下,选择“检查包”。结果是安装失败。日志文件如下所示。

我尝试编译另一个包含 C 代码的包,但也无法编译它。我尝试编译的包是 devtools v1.5 在这种情况下返回的错误是“LoadLibrary failure: %1 is not a valid Win32 application.”

有人有在 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'

【问题讨论】:

  • 等等!!!我看到 Rtool 包和 R 的版本不匹配......那怎么能成功?我还看到可能存在 64 位/32 位不匹配的提示。我不会成为最终答案的来源,因为我是 Mac 用户。
  • Rtools v3.1 支持 R v3.0.x 到 v3.1.x(参见 cran.r-project.org/bin/windows/Rtools)。我也确实看到了 64 位/32 位不匹配。我发现奇怪的是 Win Builder 服务也返回相同的错误 - 我很想知道包的维护者如何为 Windows 编译二进制文件。我已将问题通过电子邮件发送给他们,但尚未收到回复。

标签: c r gcc glpk


【解决方案1】:

看起来有几件事出了问题:

  1. 正在预编译对象文件,但未清除。

  2. 因为这些目标文件正在被预编译,而且看起来它们是为 64 位架构编译的,所以当您尝试在 32 位构建中使用这些文件时,安装过程会失败。

这里的修复将删除所有这些*.o 文件(我想它们需要作为R CMD build 步骤的一部分进行编译),然后生成的压缩包可以是R CMD checked。

您应该考虑安装更新版本的 RStudio 和 devtools,并确保您使用 devtools 来处理构建过程——它可能会在这里为您提供帮助。

【讨论】:

    猜你喜欢
    • 2019-11-15
    • 1970-01-01
    • 2012-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多