robotology-dependencies / ipopt-matlab-interface-cmake

CMake-based build system to the IPOPT MATLAB/Octave Interface.
2 stars 2 forks source link

Can not use ipopt binding #4

Open VenusPasandi opened 6 years ago

VenusPasandi commented 6 years ago

@traversaro I went through the ipopt installation instruction and at the end added the mex folder path to the MATLAB. Now command help ipopt works but when I run the examplehs051, I receive following error,

Attempt to execute SCRIPT ipopt as a function:
/home/vpasandi/ipopt-matlab-interface-cmake/build/install/mex/ipopt.m

Error in examplehs051 (line 33)
  [x info] = ipopt(x0,funcs,options);
aikolina commented 6 years ago

The above problem has been fixed and it was due to the fact that ${CMAKE_INSTALL_PREFIX}/mex does not contain any MEX-file. The MEX-file (ipopt.exa64) is instead stored in <prefix>/ipopt-matlab-interface-cmake/build/matlab where <prefix> is location where you cloned the repository.

To fix the problem, it has been sufficient to set the environment variable MATLABPATH in the .bashrc as follows:

export MATLABPATH=/home/adinale/src/ipopt-matlab-interface-cmake/build/matlab:/home/adinale/src/ipopt-matlab-interface-cmake/build/install/mex

Nevertheless, I was still not able to run examplehs051, because the ipopt.exa64 does not seem to be a valid MEX-file. Here is the new error that I get:

>> [x, info] = examplehs051
Invalid MEX-file '/home/adinale/src/ipopt-matlab-interface-cmake/build/matlab/ipopt.mexa64':
/home/adinale/src/ipopt-matlab-interface-cmake/build/matlab/ipopt.mexa64: undefined symbol: _ZN5Ipopt7Journal4NameB5cxx11Ev.

Error in examplehs051 (line 33)
  [x info] = ipopt(x0,funcs,options);
aikolina commented 6 years ago

I remembered that I had a similar issue when building iDyntree bindings. So I decided to follow the suggestion given on WB-Toolbox troubleshooting and run Matlab by preloading libstdc++.so through the LD_PRELOAD environment variable. Unfortunately, this did not solve the above-mentioned problem (undefined symbol: ZN5Ipopt7Journal4NameB5cxx11Ev).

Then I have found that in the troubleshooting of Pypopt (IpOpt bindings for Python), they suggest to do the following:

[...] install Ipopt from source and set the IPOPT_INCLUDE_DIR and IPOPT_LIBRARY_DIR environment variables to your Ipopt installation.

I did not install IpOpt from source yet but I am planning to go for this option since it looks like I have exactly the same problem as Pypopt. @traversaro What do you think about it? Would I have to worry about compatibilities issue with robotology-superbuild?

traversaro commented 6 years ago

This seems a linking problem in the bindings file ipopt.mexa64 . I suggest the following steps:

Note : all the mentioned commands are available only on Linux, let me know if you are on another OS because there are equivalent commands. If @diegoferigo is around, he can give you some more info on this linking issues.

VenusPasandi commented 6 years ago

In a very simple way, I downloaded last version of ipopt mex file that is available for download at https://www.coin-or.org/download/binary/Ipopt/ and fortunately it works. About the ipopt instruction that written by @traversaro, I think following quote from https://www.coin-or.org/Ipopt/documentation/node18.html#sec.matlab.build would be helpful:

In practice, it has been found easier to install and use the MATLAB interface by disabling compilation of the shared libraries, and use only static libraries instead. However, these static libraries need to be built in a way that allow using them in a shared library, i.e., they need to build with position-independent code. This is achieved with the configure script flags --disable-shared --with-pic.