[petsc-dev] Matlab interface issue

Vaclav Hapla vaclav.hapla at erdw.ethz.ch
Mon Apr 16 06:41:20 CDT 2018


Hello

I need to compile PETSc with MATLAB interface on Mac OS.

First thing is that Mex supports only Xcode or Intel compilers, not GCC. So I compiled PETSc with Xcode, using options
  --with-cc="/usr/bin/xcrun -sdk macosx10.13 clang" --with-matlab --with-matlab-arch=maci64 --with-matlab-engine --with-mpi=0

But the target "matlabcodes" (in src/sys/classes/viewer/impls/socket/matlab/makefile) was failing with
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64

After some investigation I found out the problem lies in specifying environment variables to the mex compiler. Mex has some predefined values of these variables and fails if we override them. According to MATLAB documentation, it should be possible to just append what we need, e.g.
  LDFLAGS='${LDFLAGS} ${PETSC_EXTERNAL_LIB_BASIC}'
but this apparently does not work as excepted, some predefined options are removed this way. I was debugging that by adding -v to ${MATLAB_MEX} calls in the makefile. It seems the injected LDFLAGS is interpreted _after_ something more is added to LDFLAGS by MEX (stupid).

What works for me is specifying the options directly do ${MATLAB_MEX}. This is also tricky, though, as ${MATLAB_MEX} does not accept all options, e.g. -Wl,-rpath. So I ended up with replacing
  GCC='${CC}' CC='${PCC}' CFLAGS='${COPTFLAGS} ${CC_FLAGS} ${CCPPFLAGS}' LDFLAGS='${PETSC_EXTERNAL_LIB_BASIC}'
by
  ${PETSC_CC_INCLUDES} -L${PETSC_DIR}/${PETSC_ARCH}/lib ${PETSC_LIB_BASIC}
in src/sys/classes/viewer/impls/socket/matlab/makefile. See the attached patch. This at least compiled.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 1800 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20180416/511fd67c/attachment.obj>
-------------- next part --------------


Do you think this could break anything? Do you have some better idea?

BTW It would be better if the matlabcodes target could be turned off by configure, if one is interested only in using MATLAB Engine and wants to avoid problems with the mex compiler.

Thanks,
Vaclav


More information about the petsc-dev mailing list