编译MEX文件的问题(找不到-lstdc ++)

时间:2014-07-24 01:33:40

标签: matlab mex

所以我一直在尝试使用mex来编译这段代码。问题是似乎无法找到lstdc++lpthreadlibm出于任何不兼容的原因。我的/usr/lib32文件夹如下所示:

    iggy@ThinkpadX1:~/Applications/Matlab_2012a/bin$ ls /usr/lib32/
crt1.o    libanl.so           libc_nonshared.a  libg.a            libmcheck.a       libnss_files.so         libpthread.so         librt.so             libz.so.1
crti.o    libBrokenLocale.a   libcrypt.a        libgcc_s.so.1     libm.so           libnss_hesiod.so        libquadmath.so.0      libstdc++.so.6       libz.so.1.2.3.4
crtn.o    libBrokenLocale.so  libcrypt.so       libgomp.so.1      libnsl.a          libnss_nisplus.so       libquadmath.so.0.0.0  libstdc++.so.6.0.16  Mcrt1.o
gconv     libbsd-compat.a     libc.so           libgomp.so.1.0.0  libnsl.so         libnss_nis.so           libresolv.a           libthread_db.so      Scrt1.o
gcrt1.o   libc.a              libdl.a           libieee.a         libnss_compat.so  libpthread.a            libresolv.so          libutil.a
libanl.a  libcidn.so          libdl.so          libm.a            libnss_dns.so     libpthread_nonshared.a  librt.a               libutil.so

我收到的错误如下:

K>> make_csolve

**************************************************************************
  Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected. 
           Using -compatibleArrayDims. In the future, MATLAB will require
           the use of -largeArrayDims and remove the -compatibleArrayDims
           option. For more information, see:
           http://www.mathworks.com/help/techdoc/matlab_external/bsflnue-1.html
**************************************************************************

/home/iggy/Applications/Matlab_2012a/bin/mex: 1: /home/iggy/Applications/Matlab_2012a/bin/util/oscheck.sh: /lib64/libc.so.6: not found
/home/iggy/Applications/Matlab_2012a/bin/mex: 1: /home/iggy/Applications/Matlab_2012a/bin/util/oscheck.sh: /lib64/libc.so.6: not found
-> mexopts.sh sourced from directory (DIR = $MATLAB/bin)
   FILE = /home/iggy/Applications/Matlab_2012a/bin/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /home/iggy/Applications/Matlab_2012a
->    CC                    = gcc-4.4
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = -Wl,-rpath-link,/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -L/usr/lib32 -L/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -lmx -lmex -lmat -lm  -lstdc++
         arguments          =  -DMX_COMPAT_32
->    CXX                   = g++-4.4
->    CXX flags:
         CXXFLAGS           = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = -Wl,-rpath-link,/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -L/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    FC                    = gfortran
->    FC flags:
         FFLAGS             = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -Wl,-rpath-link,/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -L/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    LD                    = gcc-4.4
->    Link flags:
         LDFLAGS            = -pthread -shared -Wl,--version-script,/home/iggy/Applications/Matlab_2012a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexa64
         arguments          = 
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          = 
----------------------------------------------------------------

-> gcc-4.4 -c  -I/home/iggy/Applications/Matlab_2012a/extern/include -I/home/iggy/Applications/Matlab_2012a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -O -DNDEBUG  "csolve.c"

-> gcc-4.4 -c  -I/home/iggy/Applications/Matlab_2012a/extern/include -I/home/iggy/Applications/Matlab_2012a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -O -DNDEBUG  "ldl.c"

-> gcc-4.4 -c  -I/home/iggy/Applications/Matlab_2012a/extern/include -I/home/iggy/Applications/Matlab_2012a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -O -DNDEBUG  "matrix_support.c"

-> gcc-4.4 -c  -I/home/iggy/Applications/Matlab_2012a/extern/include -I/home/iggy/Applications/Matlab_2012a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -O -DNDEBUG  "solver.c"

-> gcc-4.4 -c  -I/home/iggy/Applications/Matlab_2012a/extern/include -I/home/iggy/Applications/Matlab_2012a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -O -DNDEBUG  "util.c"

-> gcc-4.4 -O -pthread -shared -Wl,--version-script,/home/iggy/Applications/Matlab_2012a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o  "csolve.mexa64"  csolve.o ldl.o matrix_support.o solver.o util.o  -Wl,-rpath-link,/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -L/usr/lib32 -L/home/iggy/Applications/Matlab_2012a/bin/glnxa64 -lmx -lmex -lmat -lm  -lstdc++

/usr/bin/ld: skipping incompatible /usr/lib32/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib32/libm.a when searching for -lm
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib32/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib32/libpthread.a when searching for -lpthread
collect2: ld returned 1 exit status

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

Error using mex (line 206)
Unable to complete successfully.

Error in make_csolve (line 10)
mex -v csolve.c ldl.c matrix_support.c solver.c util.c

我将非常感谢任何建议(我使用的是64位运行MATLAB R2012a的Ubuntu 12.04)。

1 个答案:

答案 0 :(得分:0)

/ use / lib32中的库是不兼容的,因为它们是错误的体系结构(32位而不是64位)。首先尝试再次运行mex -setup。我假设您使用的是64位MATLAB(请查看ver),因为当前设置中有glnxa64文件夹。

但是,真正的错误似乎如下:

  

/ home / iggy / Applications / Matlab_2012a / bin / mex:1:/home/iggy/Applications/Matlab_2012a/bin/util/oscheck.sh:/lib64/libc.so.6:not found

由于oscheck.sh无法找到/lib64/libc.so.6,您可能需要进入包管理并查找libc和libstdc ++,安装它们并重试。但首先尝试链接到另一个文件夹中的任何现有libc.so.6。 Ubuntu的典型位置如下。

64位Ubuntu:

sudo ln -s /lib/x86_64-linux-gnu/libc.so.6 /lib64/libc.so.6

32位Ubuntu:

sudo ln -s /lib/i386-linux-gnu/libc.so.6 /lib/libc.so.6