<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">OK. But definitely it's tricky that you try to inject all PETSc compiler options to the mex wrapper which is by documentation only tested with Xcode and Intel and it's always set up just for one compiler (see <span style="color: rgb(64, 64, 64); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; white-space: nowrap; widows: 1; background-color: rgb(252, 252, 252);" class="">mex -setup)</span>.</div><div class=""><br class=""></div><div class="">Hence, I would at least vote for config option to turn off this socket mex stuff to bypass potential problems if one doesn't need it. Like --with-matlab-socket=0 or so which would just deactivate the matlabbin target. Or behave like that if --with-matlab-engine=1 and --with-matlab=0 (this currently fails with "Did not find package MATLAB needed by MatlabEngine" which is confusing anyway as it's not a standalone product).</div><div class=""><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Vaclav</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">16. 4. 2018 v 20:30, Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" class="">bsmith@mcs.anl.gov</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hmm, I tried on my Mac and had the same problem. But then I upgraded from Matlab 2017A to 2018A and boom the problem went away and it was able to build the socket mex files without a problem.<br class=""><br class="">So my conclusion is that we shouldn't change anything in the PETSc makefiles?<br class=""><br class=""> Barry<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Apr 16, 2018, at 6:41 AM, Vaclav Hapla <<a href="mailto:vaclav.hapla@erdw.ethz.ch" class="">vaclav.hapla@erdw.ethz.ch</a>> wrote:<br class=""><br class="">Hello<br class=""><br class="">I need to compile PETSc with MATLAB interface on Mac OS.<br class=""><br class="">First thing is that Mex supports only Xcode or Intel compilers, not GCC. So I compiled PETSc with Xcode, using options<br class=""> --with-cc="/usr/bin/xcrun -sdk macosx10.13 clang" --with-matlab --with-matlab-arch=maci64 --with-matlab-engine --with-mpi=0<br class=""><br class="">But the target "matlabcodes" (in src/sys/classes/viewer/impls/socket/matlab/makefile) was failing with<br class="">Undefined symbols for architecture x86_64:<br class=""> "_main", referenced from:<br class=""> implicit entry/start for main executable<br class="">ld: symbol(s) not found for architecture x86_64<br class=""><br class="">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.<br class=""> LDFLAGS='${LDFLAGS} ${PETSC_EXTERNAL_LIB_BASIC}'<br class="">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).<br class=""><br class="">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<br class=""> GCC='${CC}' CC='${PCC}' CFLAGS='${COPTFLAGS} ${CC_FLAGS} ${CCPPFLAGS}' LDFLAGS='${PETSC_EXTERNAL_LIB_BASIC}'<br class="">by<br class=""> ${PETSC_CC_INCLUDES} -L${PETSC_DIR}/${PETSC_ARCH}/lib ${PETSC_LIB_BASIC}<br class="">in src/sys/classes/viewer/impls/socket/matlab/makefile. See the attached patch. This at least compiled.<br class=""><br class=""><br class="">Do you think this could break anything? Do you have some better idea?<br class=""><br class="">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.<br class=""><br class="">Thanks,<br class="">Vaclav<br class=""><patch><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>