链接器错误最可爱的二进制文件与 matlab

Linker Error cutest binary with matlab

我需要实现一个包含数学问题的库来测试我在 matlab 中编写的算法。该库称为 "cutest"(请参阅此处:http://ccpforge.cse.rl.ac.uk/gf/project/cutest/wiki/)。

因为我正在使用 Ubuntu,所以无法通过自制软件库安装这个东西。因此,我进行了手动安装,并且能够安装 cutest 和 problemdecoder "sifdec"(也可以从上面的页面下载)。

我现在卡住了,我需要编译一个可以被matlab使用的二进制文件。我想这与 fortran/gcc 的编译器标志和一个 32/64 位的东西有关(因为我已经在浏览其他帖子和 google)。

我得到的错误如下:

/usr/bin/ld: i386 architecture of input file `/home/beck/CUTEst/cutest
/objects/pc64.lnx.gfo/double/mcutest.o' is incompatible with i386:x86-64 
output
/usr/bin/ld: /home/beck/CUTEst/cutest/objects/pc64.lnx.gfo/double
/mcutest.o: file class ELFCLASS32 incompatible with ELFCLASS64
/usr/bin/ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status

mex: link of ' "mcutest.mexa64"' failed.

mex 文件来自 matlab,我还没有修改它(也没有修改 mex 的选项文件)。

我通过终端安装(自动)创建的 makefile "pc64.lnx.gfo" 的设置如下:

#  Architecture dependent makefile
#  (automatically generated by install_cutest)

VERSION = pc64.lnx.gfo

#  Basic system commands

CP = /bin/cp
MV = /bin/mv
RM = /bin/rm -f
SED = /bin/sed
GREP = /bin/grep
AR = /usr/bin/ar
RANLIB = /usr/bin/ranlib

#  Directory for binaries

PRECIS = double
OBJ = $(CUTEST)/objects/$(VERSION)/$(PRECIS)
OBJS = $(CUTEST)/objects/$(VERSION)/single
OBJD = $(CUTEST)/objects/$(VERSION)/double
MOD = $(CUTEST)/modules/$(VERSION)/$(PRECIS)
SEDS = $(CUTEST)/seds/$(PRECIS).sed
MVMODS = $(MV) -f $(OBJ)/*.mod $(MOD)/ || true

#  Compiler options

FORTRAN = gfortran-4.7
BASIC = -c -fno-second-underscore -fPIC
MODULES =  -I$(MOD)
OPTIMIZATION = -O
NOOPTIMIZATION = -O0
DEBUG = 
OPENMP = -fopenmp
F77 = -ffixed-form
F90 = 
F95 = 
NOFMAIN = 
USUAL = 
SPECIAL = 
F77SUFFIX = f90
F95SUFFIX  = f90
TIMER = GEN
NOT95 = IS95
NOT64 = IS64

AMPLDIR   = 
CC        = gcc-4.7
CCBASIC   = -c -ansi -pedantic -fPIC
CCONDEF   = 
CCDEBUG   = 
CCFFLAGS  = -lgfortran

#  Special flags


#  Libraries

BLAS = 
LAPACK = 
CUTESTUSED = 

#  Shell used

BINSHELL = sh

#  Set directories for optional packages

include $(CUTEST)/src/makedefs/packages

#  Body of makefile

include $(PWD)/makemaster

非常感谢任何形式的帮助,这个问题让我无法进一步完成我的硕士论文。

编辑:添加了 gcc-4.7/gfortran-4.7 -v

的输出

gcc-4.7 -v:

Using built-in specs.
COLLECT_GCC=gcc-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.4-3ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.4 (Ubuntu/Linaro 4.7.4-3ubuntu3)

gfortran-4.7 -v:

Using built-in specs.
COLLECT_GCC=gfortran-4.7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.4-3ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.4 (Ubuntu/Linaro 4.7.4-3ubuntu3) 

在我大学的一位学术成员的帮助下,我能够解决这个问题。如果有人 has/will 遇到同样的问题,这对我有用:

由于工具链是 64 位的,而唯一以 32 位生成的文件是 mcutest.o 错误必须结合 mex 编译(因为只有这个文件是用matlab 的 mex 编译器)。

在文件夹结构中有一个名为 makemaster 的文件,它包含在安装过程中为 gfortran 和 gcc 选择的设置,还有 mex 的设置(我还没有被要求修改)。然而,经过一些测试,在 MFLAGS 中添加行 CFLAGS='$(CFLAGS)' 导致了一个 64 位输出文件并且错误不再发生。

谢谢你的帮助!