Symbolic link to compile code using 32-bit libraries on 64-bit Ubuntu 12.10
I am trying to get mex C code using Matlab 32 bit 2012a on Ubuntu 12.10 64 bit
I have downloaded all possible libraries (gcc 4.7, build-essential, libs-32, etc.) however I am getting the following error
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.so when searching for -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.a when searching for -lgomp
/usr/bin/ld: cannot find -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
I found that this problem can be solved by setting a symbolic link from 64-bit libraries to 32-bit ones. I tried to create different links but couldn't finish compiling.
Thanks in advance.
UPDATE 1
gcc-multilib is missing, so after
sudo apt-get install gcc-multilib
I am getting the following errors:
Warning: You are using gcc version "4.7.2-2ubuntu1)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
My mexopts.sh looks like
CC='gcc'
CFLAGS='-ansi -D_GNU_SOURCE'
CFLAGS="$CFLAGS -fPIC -pthread -m32"
CFLAGS="$CFLAGS -fexceptions"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64"
CLIBS="$RPATH $MLIBS -lm"
COPTIMFLAGS='-O -DNDEBUG'
CDEBUGFLAGS='-g'
CLIBS="$CLIBS -lstdc++"
there is -m32, however I am not sure if it should be written that way. Can anyone please elaborate on how to edit mexopts.sh to make Matlab look at 32 bit libraries?
UPDATE 2
after looking at Binding using g ++ can't find -lstdc ++
I tried to install g ++ - multilib
sudo apt-get install g++-multilib
Now the errors look like:
/usr/bin/ld: i386:x86-64 architecture of input file `bin/fv_cache.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `bin/obj_func.o' is incompatible with i386 output
...
source to share
- First make sure you can build a 32-bit executable from the command line by executing gcc (more details here: 32-bit application on 64-bit Linux )
- On the matlab command line, execute
mex -setup
and selectgcc
as compiler. At the end you will receive a message about the location of "mexopts.sh" (usually ~ / .matlab // mexopts.sh) - Try "mex".
- If failed to open
mexopts.sh
and check if the parameter is-m32
inCFLAGS
. If not, add it.
source to share