質問

I'm trying to build a C program on Matlab 2012a, through the command:

mex mat_trans2.c

And I'm getting this error:

/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

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

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

Some time ago I was able to build .c files, I don't know what is happening now! Maybe something has changed after a system upgrade on my Kubuntu 12.04 64 bit.

Is there someone who know how to solve this?

Thank you!!!!

Edit: I edit the message to reply at Shai. Running:

mex -v mat_trans2.c

I get:

**************************************************************************
  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/mafalda/MATLAB/bin/mex: 1: /home/mafalda/MATLAB/bin/util/oscheck.sh: /lib64/libc.so.6: not found
/home/mafalda/MATLAB/bin/mex: 1: /home/mafalda/MATLAB/bin/util/oscheck.sh: /lib64/libc.so.6: not found
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
   FILE = /home/mafalda/.matlab/R2012a/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /home/mafalda/MATLAB
->    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/mafalda/MATLAB/bin/glnxa64 -L/home/mafalda/MATLAB/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/mafalda/MATLAB/bin/glnxa64 -L/home/mafalda/MATLAB/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    FC                    = gfortran-4.4
->    FC flags:
         FFLAGS             = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -Wl,-rpath-link,/home/mafalda/MATLAB/bin/glnxa64 -L/home/mafalda/MATLAB/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DMX_COMPAT_32
->    LD                    = gcc-4.4
->    Link flags:
         LDFLAGS            = -pthread -shared -Wl,--version-script,/home/mafalda/MATLAB/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/mafalda/MATLAB/extern/include -I/home/mafalda/MATLAB/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -O -DNDEBUG  "mat_trans2.c"

-> gcc-4.4 -O -pthread -shared -Wl,--version-script,/home/mafalda/MATLAB/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o  "mat_trans2.mexa64"  mat_trans2.o  -Wl,-rpath-link,/home/mafalda/MATLAB/bin/glnxa64 -L/home/mafalda/MATLAB/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++

/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status

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

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

I would say the problem is that /lib64/libc.so.6: cannot be found

Plus:

locate libstdc++.so.6
/home/mafalda/MATLAB/bin/glnxa64/libstdc++.so.6
/home/mafalda/MATLAB/bin/glnxa64/libstdc++.so.6.0.13
/home/mafalda/MATLAB/sys/os/glnxa64/libstdc++.so.6
/home/mafalda/MATLAB/sys/os/glnxa64/libstdc++.so.6.0.16
/home/mafalda/MATLAB/toolbox/edalink/foundation/hdllink/scripts/linux32/libstdc++.so.6
/home/mafalda/MATLAB/toolbox/edalink/foundation/hdllink/scripts/linux32/libstdc++.so.6.0.13
/home/mafalda/MATLAB/toolbox/sldv/sldv/polyspace-dvo/lib/x86-linux/libstdc++.so.6
/usr/lib/i386-linux-gnu/libstdc++.so.6
/usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
/usr/lib32/libstdc++.so.6
/usr/lib32/libstdc++.so.6.0.16
役に立ちましたか?

解決 2

Trivial solution, I hadn't check the most obvious thing:

$ sudo apt-get install libstdc++6-4.4-dev

他のヒント

Try launching MATLAB with:

$ LD_PRELOAD=/usr/lib/libstdc++.so.6 matlab

(or whatever is the actual location on your system).

You could also create a symlink in /lib64/libc.so.6 pointing to it

I was getting the same error, after hours of trying different solutions it looks like I found out how to solve it in my case. The solution was to simply create a symlink from libstdc++.so.6 to libstdc++.so . So: cd to /usr/lib/x86_64-linux-gnu/ and run sudo ln -s libstdc++.so.6 libstdc++.so. I hope it will work in your cases also.

Try install the package:

sudo yum install libstdc++-static

Since I don't have the reputation to comment, I would like to say that answer by @mafalda worked for me. I just had to replace 4.4 by 4.7 in his answer because I am using gcc-4.7 compiler. Even the latest release of MATLAB (R2016a as of now) supports only gcc-4.7.x (and not 4.8.x (which is latest for now)), I wanted to point out if someone uses this answer, just replace 4.4 by 4.x where x depends on your gcc complier version.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top