[Ipopt-tickets] [Ipopt] #232: Problem in compiling matlab interface on MacOSX Maverick
Ipopt
coin-trac at coin-or.org
Wed Apr 23 08:22:48 EDT 2014
#232: Problem in compiling matlab interface on MacOSX Maverick
---------------------+------------------------
Reporter: ricwtk | Owner: ipopt-team
Type: defect | Status: new
Priority: high | Component: Ipopt
Version: 3.11 | Severity: critical
Resolution: | Keywords:
---------------------+------------------------
Comment (by tomaszG):
Hello, I am having a very similar issue:
I am using
newest version of Ipopt 3.11 from the svn
Matlab 8.2.0.701 (R2013b)
GCC 4.7.1
Xcode 5.1.1
Configuring the install with
{{{
../configure --disable-shared CC=gcc
}}}
make, make test, make install go fine
then using the files
Makefile
{{{
# Copyright (C) 2007, 2009 Peter Carbonetto. All Rights Reserved.
# This code is published under the Eclipse Public License.
#
# Author: Peter Carbonetto
# Dept. of Computer Science
# University of British Columbia
# May 19, 2007
# INSTRUCTIONS: Please modify the following few variables. See the
# Ipopt documentation (Ipopt/doc/documentation.pdf) for more details.
# This variable corresponds to the base directory of your MATLAB
# installation. This is the directory so that in its 'bin/'
# subdirectory you see all the matlab executables (such as 'matlab',
# 'mex', etc.)
MATLAB_HOME = /Applications/MATLAB_R2013b.app
# Set the suffix for matlab mex files. The contents of the
# $(MATLAB_HOME)/extern/examples/mex directory might be able to help
# you in your choice.
MEXSUFFIX = mexmaci64
# This is the command used to call the mex program. Usually, it is
# just "mex". But it also may be something like
# /user/local/R2006b/bin/mex if "mex" doesn't work.
MEX = $(MATLAB_HOME)/bin/mex
#MEX = "$(MATLAB_HOME)/sys/perl/win32/bin/perl" "`$(CYGPATH_W)
"$(MATLAB_HOME)/bin/mex.pl"`"
#############################################################################
# Do not modify anything below unless you know what you're doing.
exec_prefix = ${prefix}
prefix = /Users/tomasz/Documents/CoinIpopt/build
libdir = ${exec_prefix}/lib
CXX = g++
CXXFLAGS = -O3 -pipe -DNDEBUG -Wparentheses -Wreturn-type -Wcast-qual
-Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas
-Wno-long-long -DIPOPT_BUILD -DMATLAB_MEXFILE # -DMWINDEXISINT
LDFLAGS = $(CXXFLAGS) -framework vecLib #-static-libgcc -static-
libstdc++
# Include directories (we use the CYGPATH_W variables to allow compilation
with Windows compilers)
INCL =
`PKG_CONFIG_PATH=/Users/tomasz/Documents/CoinIpopt/build/lib64/pkgconfig:/Users/tomasz/Documents/CoinIpopt/build/lib/pkgconfig:/Users/tomasz/Documents/CoinIpopt/build/share/pkgconfig:
pkg-config --cflags ipopt`
#INCL = -I`$(CYGPATH_W)
/Users/tomasz/Documents/CoinIpopt/build/include/coin`
# Linker flags
LIBS =
`PKG_CONFIG_PATH=/Users/tomasz/Documents/CoinIpopt/build/lib64/pkgconfig:/Users/tomasz/Documents/CoinIpopt/build/lib/pkgconfig:/Users/tomasz/Documents/CoinIpopt/build/share/pkgconfig:
pkg-config --libs ipopt | sed -e 's/-framework vecLib//g'`
##LIBS = -link -libpath:`$(CYGPATH_W)
/Users/tomasz/Documents/CoinIpopt/build/lib` libipopt.lib -framework
vecLib -framework vecLib -lm -ldl
#LIBS = -L/Users/tomasz/Documents/CoinIpopt/build/lib -lipopt `echo
-framework vecLib -framework vecLib -lm -ldl | sed -e 's/-framework
vecLib//g'`
LIBS_STATIC = $(LIBS)
#LIBS_STATIC = $$(echo " $(LIBS) " | sed -e "s| -lgfortran | `gfortran
-print-file-name=libgfortran.a` |g" -e "s| -lquadmath | `gfortran -print-
file-name=libquadmath.a` |g")
##LIBS_STATIC = $$(echo " $(LIBS) " | sed -e 's|
-Wl,-Bdynamic,-lmwma57,-Bstatic | -lmwma57 |g')
# mex doesn't understand -Wl,-Bdynamic,-lmwma57,-Bstatic on Windows
# The following is necessary under cygwin, if native compilers are used
CYGPATH_W = echo
#MEXFLAGCXX =
MEXFLAGCXX = -cxx
MEXFLAGS = -v $(MEXFLAGCXX) -O CC="$(CXX)" CXX="$(CXX)" LD="$(CXX)"
\
COPTIMFLAGS="$(CXXFLAGS)" CXXOPTIMFLAGS="$(CXXFLAGS)" \
LDOPTIMFLAGS="$(LDFLAGS)"
TARGET = ipopt.$(MEXSUFFIX)
OBJS = matlabexception.o \
matlabfunctionhandle.o \
matlabjournal.o \
iterate.o \
ipoptoptions.o \
options.o \
sparsematrix.o \
callbackfunctions.o \
matlabinfo.o \
matlabprogram.o \
ipopt.o
SRCDIR = ../../../../../Ipopt/contrib/MatlabInterface/src
VPATH = $(SRCDIR)
all: $(TARGET)
install: $(TARGET)
if test -d $(libdir); then : ; else mkdir $(libdir); fi
cp $(SRCDIR)/../ipopt.m $(SRCDIR)/../ipopt_auxdata.m $(TARGET)
$(libdir)
uninstall:
rm -f $(libdir)/ipopt.m $(libdir)/ipopt_auxdata.m
$(libdir)/ipopt.$(MEXSUFFIX)
$(TARGET): $(OBJS)
make mexopts
$(MEX) $(MEXFLAGS) $(LIBS_STATIC) -output $@ $^
%.o: %.cpp
../../../../libtool --tag=CXX --mode=compile \
$(CXX) $(CXXFLAGS) $(INCL) -I"$(MATLAB_HOME)/extern/include" \
-o $@ -c $^
clean:
rm -f $(OBJS) *.lo $(TARGET)
distclean: clean
GM_ADD_LIBS_STATIC =
#GM_ADD_LIBS_STATIC = GM_ADD_LIBS="-static $$GM_ADD_LIBS";
# make mexopts applies a set of fixes to mexopts.sh on Mac,
# or mexopts.bat on Windows (if that file was generated
# by Gnumex to use gcc via Cygwin or MinGW)
mexopts:
case `uname` in \
Darwin*) \
if ! test -e mexopts.sh; then \
sed -e 's/-arch $$ARCHS//g' \
$(MATLAB_HOME)/bin/mexopts.sh > mexopts.sh; \
SDKROOT=`grep -m1 'SDKROOT=' mexopts.sh | sed -e
's/SDKROOT=//g'`; \
if ! test -d $$SDKROOT; then \
sed -e 's/-arch $$ARCHS//g' \
-e 's/-isysroot $$SDKROOT//g' \
-e 's/-Wl,-syslibroot,$$SDKROOT//g' \
$(MATLAB_HOME)/bin/mexopts.sh > mexopts.sh; \
fi; \
fi \
;; \
MINGW*) \
if ! test -e mexopts.bat; then \
echo Warning: no mexopts.bat found. You will probably need
to run Gnumex to generate this file. Call \"make gnumex\" then try again.;
\
else \
libdirwin=$$(cd $(libdir); cmd /c 'for %i in (.) do @echo
%~fi' | sed 's|\\|/|g'); \
mingwlibdirwin=$$(cd /mingw/lib; cmd /c 'for %i in (.) do
@echo %~fi' | sed 's|\\|/|g'); \
GM_ADD_LIBS=$$(echo "-llibmx -llibmex -llibmat $(LIBS) " | \
sed -e "s| -L$(libdir) | -L$$libdirwin |g" \
-e "s| -L/mingw/lib | -L$$mingwlibdirwin |g"); \
$(GM_ADD_LIBS_STATIC) \
cp mexopts.bat mexopts.bat.orig; \
sed -e 's|COMPILER=gcc|COMPILER=g++|' -e
's|GM_MEXLANG=c$$|GM_MEXLANG=cxx|' \
-e "s|GM_ADD_LIBS=-llibmx -llibmex
-llibmat$$|GM_ADD_LIBS=$$GM_ADD_LIBS|" \
mexopts.bat.orig > mexopts.bat; \
fi \
;; \
CYGWIN*) \
if ! test -e mexopts.bat; then \
echo Warning: no mexopts.bat found. You will probably need
to run Gnumex to generate this file. Call \"make gnumex\" then try again.;
\
else \
libdirwin=`cygpath -m $(libdir)`; \
cyglibdirwin=`cygpath -m /usr/lib`; \
GM_ADD_LIBS=$$(echo "-llibmx -llibmex -llibmat $(LIBS) " | \
sed -e "s| -L$(libdir) | -L$$libdirwin |g" \
-e "s| -L/usr/lib/| -L$$cyglibdirwin/|g"); \
$(GM_ADD_LIBS_STATIC) \
cp mexopts.bat mexopts.bat.orig; \
sed -e 's|COMPILER=gcc|COMPILER=g++|' -e
's|GM_MEXLANG=c$$|GM_MEXLANG=cxx|' \
-e "s|GM_ADD_LIBS=-llibmx -llibmex
-llibmat$$|GM_ADD_LIBS=$$GM_ADD_LIBS|" \
mexopts.bat.orig > mexopts.bat; \
fi \
;; \
esac
# make gnumex opens a Matlab session and calls the Gnumex tool to
# generate mexopts.bat set up for using gcc via Cygwin or MinGW
gnumex:
if ! test -d "$(SRCDIR)/../gnumex"; then \
echo "Warning: no gnumex folder found. Run \"cd `dirname
$(SRCDIR)`; ./get.Gnumex\" first."; \
else \
GM_COMMANDS="oldpwd=pwd; cd $(SRCDIR)/../gnumex;
gnumex('startup'); \
gnumexopts=gnumex('defaults'); gnumexopts.precompath=[pwd
'\libdef']; \
gnumexopts.optfile=[oldpwd '\mexopts.bat'];"; \
case `uname` in \
MINGW*) \
echo Use gnumex in Matlab to create mexopts.bat file, then
close this new instance of Matlab.; \
"$(MATLAB_HOME)/bin/matlab" -wait -r "$$GM_COMMANDS \
gnumexopts.mingwpath=fileparts(gnumexopts.gfortpath);
gnumex('struct2fig',gnumexopts)" \
;; \
CYGWIN*) \
echo Use gnumex in Matlab to create mexopts.bat file, then
close this new instance of Matlab.; \
"$(MATLAB_HOME)/bin/matlab" -wait -r "$$GM_COMMANDS
gnumexopts.environ=3; gnumex('struct2fig',gnumexopts)" \
;; \
esac \
fi
}}}
mexopts.sh
{{{
#
# mexopts.sh Shell script for configuring MEX-file creation script,
# mex. These options were tested with the specified
compiler.
#
# usage: Do not call this file directly; it is sourced by the
# mex shell script. Modify only if you don't like the
# defaults after running mex. No spaces are allowed
# around the '=' in the variable assignment.
#
# Note: For the version of system compiler supported with this release,
# refer to the Supported and Compatible Compiler List at:
# http://www.mathworks.com/support/compilers/current_release/
#
#
# SELECTION_TAGs occur in template option files and are used by MATLAB
# tools, such as mex and mbuild, to determine the purpose of the contents
# of an option file. These tags are only interpreted when preceded by '#'
# and followed by ':'.
#
#SELECTION_TAG_MEX_OPT: Template Options file for building MEX-files
#
# Copyright 1984-2011 The MathWorks, Inc.
# $Revision: 1.78.4.18 $ $Date: 2012/11/15 06:22:54 $
#----------------------------------------------------------------------------
#
TMW_ROOT="$MATLAB"
MFLAGS=''
if [ "$ENTRYPOINT" = "mexLibrary" ]; then
MLIBS="-L$TMW_ROOT/bin/$Arch -lmx -lmex -lmat -lmwservices -lut"
else
MLIBS="-L$TMW_ROOT/bin/$Arch -lmx -lmex -lmat"
fi
case "$Arch" in
Undetermined)
#----------------------------------------------------------------------------
# Change this line if you need to specify the location of the MATLAB
# root directory. The script needs to know where to find utility
# routines so that it can determine the architecture; therefore, this
# assignment needs to be done while the architecture is still
# undetermined.
#----------------------------------------------------------------------------
MATLAB="$MATLAB"
;;
glnx86)
#----------------------------------------------------------------------------
echo "Error: Did not imbed 'options.sh' code"; exit 1 #imbed options.sh
glnx86 12
#----------------------------------------------------------------------------
;;
glnxa64)
#----------------------------------------------------------------------------
RPATH="-Wl,-rpath-link,$TMW_ROOT/bin/$Arch"
# StorageVersion: 1.0
# CkeyName: GNU C
# CkeyManufacturer: GNU
# CkeyLanguage: C
# CkeyVersion:
# CkeyLinkerName: GNU ld
# CkeyLinkerVersion:
CC='gcc'
CFLAGS='-ansi -D_GNU_SOURCE'
CFLAGS="$CFLAGS -fexceptions"
CFLAGS="$CFLAGS -fPIC -fno-omit-frame-pointer -pthread"
CLIBS="$RPATH $MLIBS -lm"
COPTIMFLAGS='-O -DNDEBUG'
CDEBUGFLAGS='-g'
CLIBS="$CLIBS -lstdc++"
#
# C++keyName: GNU C++
# C++keyManufacturer: GNU
# C++keyLanguage: C++
# C++keyVersion:
# C++keyLinkerName: GNU ld
# C++keyLinkerVersion:
CXX='g++'
CXXFLAGS='-ansi -D_GNU_SOURCE'
CXXFLAGS="$CXXFLAGS -fPIC -fno-omit-frame-pointer -pthread"
CXXLIBS="$RPATH $MLIBS -lm"
CXXOPTIMFLAGS='-O -DNDEBUG'
CXXDEBUGFLAGS='-g'
#
# FortrankeyName: gfortran
# FortrankeyManufacturer: GNU
# FortrankeyLanguage: Fortran
# FortrankeyVersion:
# FortrankeyLinkerName: GNU ld
# FortrankeyLinkerVersion:
#
FC='gfortran'
FFLAGS='-fexceptions -fbackslash'
FFLAGS="$FFLAGS -fPIC -fno-omit-frame-pointer"
FLIBS="$RPATH $MLIBS -lm"
FOPTIMFLAGS='-O'
FDEBUGFLAGS='-g'
#
LD="$COMPILER"
LDEXTENSION='.mexa64'
LDFLAGS="-pthread -shared -Wl,--version-
script,$TMW_ROOT/extern/lib/$Arch/$MAPFILE -Wl,--no-undefined"
LDOPTIMFLAGS='-O'
LDDEBUGFLAGS='-g'
#
POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
;;
sol64)
#----------------------------------------------------------------------------
echo "Error: Did not imbed 'options.sh' code"; exit 1 #imbed options.sh
sol64 12
#----------------------------------------------------------------------------
;;
mac)
#----------------------------------------------------------------------------
echo "Error: Did not imbed 'options.sh' code"; exit 1 #imbed options.sh
mac 12
#----------------------------------------------------------------------------
;;
maci)
#----------------------------------------------------------------------------
echo "Error: Did not imbed 'options.sh' code"; exit 1 #imbed options.sh
maci 12
#----------------------------------------------------------------------------
;;
maci64)
#----------------------------------------------------------------------------
# StorageVersion: 1.0
# CkeyName: Clang
# CkeyManufacturer: Apple
# CkeyLanguage: C
# CkeyVersion:
# CkeyLinkerName:
# CkeyLinkerVersion:
CC='xcrun -sdk macosx10.7 clang'
## workaround clang defect temporarily use line below
SDKROOT='/Developer/SDKs/MacOSX10.6.sdk'
# compute SDK root on the fly
# target 10.7
MW_SDKROOT_TMP="find `xcode-select -print-path` -name
MacOSX10.7.sdk"
MW_SDKROOT=`$MW_SDKROOT_TMP`
MACOSX_DEPLOYMENT_TARGET='10.7'
ARCHS='x86_64'
CFLAGS="-fno-common -isysroot $MW_SDKROOT -mmacosx-version-
min=$MACOSX_DEPLOYMENT_TARGET"
CFLAGS="$CFLAGS -fexceptions"
CLIBS="$MLIBS"
COPTIMFLAGS='-O2 -DNDEBUG'
CDEBUGFLAGS='-g'
#
CLIBS="$CLIBS -lstdc++"
# C++keyName: Clang++
# C++keyManufacturer: Apple
# C++keyLanguage: C++
# C++keyVersion:
# C++keyLinkerName:
# C++keyLinkerVersion:
/Users/tomasz/Documents/CoinIpopt/build/Ipopt/contrib/MatlabInterface/src/mexopts.sh
CXX='xcrun -sdk macosx10.7 clang++'
CXXFLAGS="-fno-common -fexceptions -isysroot $MW_SDKROOT
-mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
CXXLIBS="$MLIBS -lstdc++"
CXXOPTIMFLAGS='-O2 -DNDEBUG'
CXXDEBUGFLAGS='-g'
#
# FortrankeyName: GNU Fortran
# FortrankeyManufacturer: GNU
# FortrankeyLanguage: Fortran
# FortrankeyVersion:
# FortrankeyLinkerName:
# FortrankeyLinkerVersion:
FC='gfortran'
FFLAGS='-fexceptions -m64 -fbackslash'
FC_LIBDIR=`$FC -print-file-name=libgfortran.a 2>&1 | sed -n
'1s/\/*libgfortran\.dylib//p'`
FC_LIBDIR2=`$FC -print-file-name=libgfortranbegin.a 2>&1 | sed
-n '1s/\/*libgfortranbegin\.a//p'`
FLIBS="$MLIBS -L$FC_LIBDIR -lgfortran -L$FC_LIBDIR2
-lgfortranbegin"
FOPTIMFLAGS='-O'
FDEBUGFLAGS='-g'
#
LD="$CC"
LDEXTENSION='.mexmaci64'
LDFLAGS=" $MW_SDKROOT -mmacosx-version-
min=$MACOSX_DEPLOYMENT_TARGET"
LDFLAGS="$LDFLAGS -bundle
-exported_symbols_list,$TMW_ROOT/extern/lib/$Arch/$MAPFILE"
LDFLAGS="$LDFLAGS -framework vecLib"
LDOPTIMFLAGS='-O'
LDDEBUGFLAGS='-g'
#
POSTLINK_CMDS=':'
#----------------------------------------------------------------------------
;;
esac
#############################################################################
#
# Architecture independent lines:
#
# Set and uncomment any lines which will apply to all architectures.
#
#----------------------------------------------------------------------------
# CC="$CC"
# CFLAGS="$CFLAGS"
# COPTIMFLAGS="$COPTIMFLAGS"
# CDEBUGFLAGS="$CDEBUGFLAGS"
# CLIBS="$CLIBS"
#
# FC="$FC"
# FFLAGS="$FFLAGS"
# FOPTIMFLAGS="$FOPTIMFLAGS"
# FDEBUGFLAGS="$FDEBUGFLAGS"
# FLIBS="$FLIBS"
#
# LD="$LD"
# LDFLAGS="$LDFLAGS"
# LDOPTIMFLAGS="$LDOPTIMFLAGS"
# LDDEBUGFLAGS="$LDDEBUGFLAGS"
#----------------------------------------------------------------------------
#############################################################################
}}}
Then make works for the interface. But when using the thing getting error:
{{{
Invalid MEX-file
'/Users/tomasz/Documents/CoinIpopt/build/lib/ipopt.mexmaci64':
dlopen(/Users/tomasz/Documents/CoinIpopt/build/lib/ipopt.mexmaci64, 6):
Symbol not found:
__gfortran_transfer_array_write
Referenced from:
/Users/tomasz/Documents/CoinIpopt/build/lib/ipopt.mexmaci64
Expected in:
/Applications/MATLAB_R2013b.app/sys/os/maci64/libgfortran.3.dylib
in /Users/tomasz/Documents/CoinIpopt/build/lib/ipopt.mexmaci64
}}}
Tried to change the fortran libraries to system ones as suggested here :
[http://issm.jpl.nasa.gov/documentation/faq/matlab/] but did not help
Otherwise the mex that you have made available strangely work on the
examples provided but not with my problem which is large. At the moment,
my example can be run with an old version of the interface that i compiled
one year ago or so, burt which makes MATlab crash very often so I was
wondering if there is a way to make it better by recompiling.
Thx
--
Ticket URL: <https://projects.coin-or.org/Ipopt/ticket/232#comment:6>
Ipopt <http://projects.coin-or.org/Ipopt>
Interior-point optimizer for nonlinear programs.
More information about the Ipopt-tickets
mailing list