3

I am trying to mex C code using 32-bit 2012a Matlab on 64-bit Ubuntu 12.10

I've 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've found that this problem can be solved by setting symbolic link from 64-bit libraries to the 32-bit ones. I tried to create different links but couldn't finish the compilation.

Thank you in advance.

UPDATE 1

gcc-multilib was missing, so after

sudo apt-get install gcc-multilib 

I get 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++"

the -m32 is there, however I am not sure if it should be written in that way. Can someone elaborate on how to edit mexopts.sh to make matlab look at 32-bit libraries?

UPDATE 2

after looking at Linking using g++ fails searching for -lstdc++

I tried to install g++-multilib

sudo apt-get install g++-multilib 

Now, errors have the form:

/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
...
Community
  • 1
  • 1
Gnattuha
  • 211
  • 3
  • 11
  • Can you build 32-bit executable by executing gcc on command line (using -m32 option?) with some dummy .c code? – durasm Feb 19 '13 at 21:40
  • I just tried that - I couldn't since gcc 4.7-multilib was missing. Thanks for pointing that out! – Gnattuha Feb 20 '13 at 14:16

1 Answers1

0
  • First make sure you can build 32-bit executable from command prompt by executing gcc (more info here: 32bit application on 64 bit Linux)
  • In matlab command prompt execute mex -setup and choose gcc as a compiler. At the end you will get a message about location of 'mexopts.sh' (usually ~/.matlab//mexopts.sh)
  • Try to "mex".
  • If not successful open mexopts.sh and check if option -m32 is in CFLAGS. If not, add it.
durasm
  • 174
  • 3
  • 10