2

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
mafalda
  • 147
  • 1
  • 4
  • 12
  • try mexing with `-v` to get more information. look at the `LD_LIBRARY_PATH` mex is using. – Shai Apr 25 '13 at 16:18
  • I deleted a message by error, the suggestion was to create a symbolic link to the real location of the file, if I understand correctly, but when I run 'ln -s /lib/x86_64-linux-gnu/libc.so.6 /lib64/libc.so.6' I get: failed to create symbolic link `/lib64/libc.so.6': File exists – mafalda Apr 25 '13 at 16:57
  • no that was me sorry, I moved my comment into an answer ;) – Amro Apr 25 '13 at 17:12

5 Answers5

2

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

Amro
  • 123,847
  • 25
  • 243
  • 454
  • Actually i'm already always launching matlab with: LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 matlab – mafalda Apr 25 '13 at 17:03
  • 1
    maybe `gcc` call needs to be told where to find `-lstdc++`, i.e `-L/path/to/lib`? First try to recreate the `mexopts.sh` file by running `mex -setup` again – Amro Apr 25 '13 at 17:07
  • ok I have probably changed something wrong because i'm getting the following message when launching matlab through the previous string: ERROR: ld.so: object '/usr/lib/x86-linux-gnu/libstdc++.so.6' from LD_PRELOAD cannot be preloaded: ignored. – mafalda Apr 25 '13 at 17:14
  • where exactly do you have `libstdc++.so.6`? run `locate` to find it. btw I found [this](http://www.mathworks.com/support/solutions/en/data/1-F68FSA/index.html?solution=1-F68FSA) that might be related – Amro Apr 25 '13 at 17:19
  • I answered updating the topic, the comment was too long! (Thank you!!) – mafalda Apr 26 '13 at 08:48
  • @mafalda: ok apparently `/lib64/libc.so.6` doesnt exist. Create a symlink as described [here](http://www.mathworks.com/support/solutions/en/data/1-F68FSA/index.html?solution=1-F68FSA). Restart MATLAB and run `mex -setup` again – Amro Apr 26 '13 at 12:15
  • yes I did it this morning, no more linking error but still the initial one.../usr/bin/ld: cannot find -lstdc++ – mafalda Apr 26 '13 at 12:19
  • @mafalda: try to manually edit your `mexopts.sh` file, and insert `-L/usr/lib/x86_64-linux-gnu` in there. I should say that Im on a Windows machine, so you have to do all the debugging :) Also worth trying: start MATLAB without messing with LD_PRELOAD and let it load its own libraries – Amro Apr 26 '13 at 12:41
  • I've tried the second thing and nothing changes, but may I ask you exactly where I have to add `-L/usr/lib/x86_64-linux-gnu` in `mexopts.sh` file? – mafalda Apr 26 '13 at 13:01
  • @mafalda: I dont have a copy of the file, but probably on the same line that mentions `-lstdc++`, so that you get `-L/usr/lib/x86_64-linux-gnu -lstdc++` (order matters). If this doesn't work, then I'm afraid I'm out of ideas :) – Amro Apr 26 '13 at 13:11
  • @mafalda: no problem, glad you found the solution – Amro Apr 29 '13 at 16:58
1

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

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

mafalda
  • 147
  • 1
  • 4
  • 12
  • 1
    For me a combination of the 2 answers worked: install libstdc++6-4.4-dev and run MATLAB with preload: `LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" matlab`. – lapis Jun 17 '13 at 20:17
1

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.

steczol
  • 11
  • 2
0

Try install the package:

sudo yum install libstdc++-static

0

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.

user3342981
  • 85
  • 2
  • 7