在Windows上编译Rglpk时出错

时间:2014-05-01 20:07:38

标签: c r gcc glpk

我需要在项目中使用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'

1 个答案:

答案 0 :(得分:0)

看起来有些事情出错:

  1. 目标文件已预先编译,但未清除。

  2. 因为这些目标文件是预编译的,看起来它们是为64位体系结构编译的,所以当你尝试在32位构建中使用它们时,安装过程barfs。

  3. 这里的修复将删除所有这些*.o文件(它们需要编译为R CMD build步骤的一部分,我想),然后生成的tarball可以是{{ 1}}编

    您应该考虑安装更新版本的RStudio和devtools,并确保使用devtools来处理构建过程 - 它可能能够帮助您。