Trouble using ipopt with casadi from source

3,639 views
Skip to first unread message

Alic Kaufmann

unread,
Jan 30, 2018, 9:56:37 AM1/30/18
to CasADi
Hi,

I tried to install Casadi and Ipopt from source. When a very basic optimization problem (in C++) :

#include<casadi/casadi.hpp>                                                    
#include<iostream>                                                              
                                                                               
using namespace std;                                                            
using namespace casadi;                                                        
                                                                               
int main()                                                                      
{                                                                              
        MX x
= MX::sym("x", 1);                                                
        MX y
= MX::sym("y", 1);                                                
        MX z
= MX::sym("z", 1);                                                
        MX f
= pow(x,2) + 100 * pow(z,2);                                      
        MX g
= z + pow((1-x), 2) - y;                                          
       
MXDict nlp = {{"f", f}, {"g", g}, {"x", MX::vertcat({x,y,z})}};        
       
Function solver = nlpsol("S","ipopt",nlp);                              
       
DMDict arg ={{"ubg", 0}, {"lbg", 0}, {"x0", DM::vertcat({0,0,0})}};    
       
DMDict res = solver(arg);                                                                          
       
return 0;                                                              
}


In my cmake file, I set the lines :
...
find_package
(IPOPT)
find_package
(CASADI)
...


This compiles just find but when I run the the small optimization program, I get :

./optimal_problem CasADi - 2018-01-30 15:43:22 WARNING(".../casadi/core/plugin_interface.hpp:292: Assertion "handle!=0" failed:
PluginInterface::load_plugin: Cannot load shared library 'libcasadi_nlpsol_ipopt.so':
   (
    Searched directories: 1. casadipath from GlobalOptions
                          2. CASADIPATH env var
                          3. PATH env var (Windows)
                          4. LD_LIBRARY_PATH env var (Linux)
                          5. DYLD_LIBRARY_PATH env var (osx)
    A library may be 'not found' even if the file exists:
          * library is not compatible (different compiler/bitness)
          * the dependencies are not found
   )
  Tried '' :
    Error code: libcasadi_nlpsol_ipopt.so: cannot open shared object file: No such file or directory
  Tried '.' :
    Error code: ./libcasadi_nlpsol_ipopt.so: cannot open shared object file: No such file or directory") [.../casadi/core/plugin_interface.hpp:148]
terminate called after throwing an instance of 'casadi::CasadiException'
  what():  .../casadi/core/plugin_interface.hpp:387: Plugin 'ipopt' is not found.
Aborted (core dumped)


I was wondering : is it correct to still use the FindCASADI.cmake from here ?

Any idea of what could go wrong here?

Best,

Alic

Alic Kaufmann

unread,
Jan 31, 2018, 9:41:45 AM1/31/18
to CasADi
Actually, it is quite strange that it is requiring the libcasadi_nlpsol_iIpopt.so since this is not in /casadi/build/lib (casadi folder I get when I download from source) nor in the sources of the Ipopt (I just downloaded the last tarball from the Ipopt website). Note that for the installation I followed exacly the instruction from here.
Moreover,
libcasadi_nlpsol_iIpopt.so is not in usr/local/lib, even though I putted this as prefix for installation. Actually, this
libcasadi_nlpsol_iIpopt.so is just in the matlab and python casadi installation folder (before, I used casadi with matlab and python) and even if I copy those in /usr/local/lib (note that my LD_LIBRARY_PATH contains usr/local/lib) and I do ldconfig, the same error message appears when I run the small optimization program.

Joel Andersson

unread,
Jan 31, 2018, 10:24:17 AM1/31/18
to CasADi
Hi,
If you build CasADi from sources, Ipopt is only built if you set WITH_IPOPT to ON during the configure step (e.g. by editing CMakeCache.txt).

Joel

Alic Kaufmann

unread,
Jan 31, 2018, 12:44:26 PM1/31/18
to CasADi
Hi Joel,

Thank you for the quick answer.
I cleared my /build folder and did

cmake -DWITH_IPOPT=ON ..

Now I get the libcasadi_nlpsol_ipopt.so in ~/casadi/build/lib.
To be sure that The library will be detected, I do

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/alic/casadi/build/lib

I recompiled the small optimization code given above but when I run I get an eror similar to the previous
one, except that there is some symbol that he cannot find :

CasADi - 2018-01-31 18:28:19 WARNING(".../casadi/core/plugin_interface.hpp:292: Assertion "handle!=0" failed:

PluginInterface::load_plugin: Cannot load shared library 'libcasadi_nlpsol_ipopt.so':
(
Searched directories: 1. casadipath from GlobalOptions
2. CASADIPATH env var
3. PATH env var (Windows)
4. LD_LIBRARY_PATH env var (Linux)
5. DYLD_LIBRARY_PATH env var (osx)
A library may be 'not found' even if the file exists:
* library is not compatible (different compiler/bitness)
* the dependencies are not found
)
Tried '' :
    Error code: /usr/local/lib/libcasadi_nlpsol_ipopt.so: undefined symbol: _ZN6casadi14OracleFunction8finalizeERKSt3mapISsNS_11GenericTypeESt4lessISsESaISt4pairIKSsS2_EEE

Joel Andersson

unread,
Jan 31, 2018, 3:04:02 PM1/31/18
to CasADi
Could you have conflicting versions of libcasadi_nlpsol_ipopt? One downloaded and one compiled from sources?

Joel

Alic Kaufmann

unread,
Feb 1, 2018, 6:15:14 AM2/1/18
to CasADi
Actually I have 3 versions of libcasadi_nlpsol_ipopt. One that I dowloaded with the python version of casadi which I have in
/home/alic/python/casadi-py27-v3.3.0/casadi/libcasadi_nlpsol_ipopt.so.
One that I downloaded with the matlab version of casadi that I have in
/home/alic/Documents/MATLAB/casadi-matlabR2014a-v3.3.0/libcasadi_nlpsol_ipopt.so
One that I downloaded from source by folllowing the procedure here and that is installed in :
/home/alic/casadi/build/lib/libcasadi_nlpsol_ipopt.so which actually is a symlink to
/home/alic/casadi/build/lib/libcasadi_nlpsol_ipopt.so.3.4 which lives in the same directory.


If I echo the LD_LIBRARY_PATH I get
/opt/ros/lunar/lib:/usr/local/lib:/home/alic/casadi/build/lib
So the only libcasadi_nlpsol_ipopt library that is on the LD path from the 3 cited above is the library I get compiling from sources
Also in my topmost cmake file I have

# toplevel CMakeLists.txt                                                      
cmake_minimum_required
(VERSION 3.2 FATAL_ERROR)                                
                                                                               
# put debugging symbols                                                        
set(CMAKE_BUILD_TYPE Debug)                                                    
                                                                               
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /home/alic/casadi/cmake)            
                                                                               
find_package
(CASADI REQUIRED)                                                  
find_package
(IPOPT REQUIRED)                                                    
                                                                               
add_subdirectory
(hovercraft)                                                    
add_subdirectory
(mylibrary)



So the find_package finds the package from the casadi downloaded from sources.
But can there still be conflicts? What should I do to resolve them?

Alic Kaufmann

unread,
Feb 1, 2018, 10:45:53 AM2/1/18
to CasADi
I also tried doing simply

g++ optimal_problem.cpp  -o optimal_problem -I/home/alic/casadi/casadi.hpp -L/home/alic/casadi/build -lcasadi -lcasadi_nlpsol_ipopt


but again I get :

/usr/bin/ld: cannot find -lcasadi_nlpsol_ipopt
collect2: error: ld returned 1 exit status


But libcasadi.so and libcasadi_nlpsol_ipopt.so are in the same directory and libcasadi.so is found whereas libcasadi_nlpsol_ipopt.so not.

Joel Andersson

unread,
Feb 1, 2018, 12:28:15 PM2/1/18
to CasADi
You are not supposed to link against libcasadi_nlpsol_ipopt.so. It's loaded at runtime, using dlopen inside CasADi's plugin loader.

Are you using the same compiler settings to compile optimal_problem.cpp as you used to compile CasADi? Are you able to run the examples in CasADi?

Joel

Joel Andersson

unread,
Feb 1, 2018, 12:30:14 PM2/1/18
to CasADi
Also, normally you don't link against the build directory. You do a "make install" step. Joel

Alic Kaufmann

unread,
Feb 2, 2018, 8:11:48 AM2/2/18
to CasADi
Thanks for the help Joel,
Actually, now it is working somehow but I am not sure what the problem was... I can now run the casadi examples and my code.


Also, normally you don't link against the build directory. You do a "make install" step. Joel

What do you mean? (I am pretty new to cmake).

Also one last question : I downloaded coinhsl-linux-x86_64 v2015.06.23 from these guys. When I open it, it seems to be a library containing hsl_ma77, hsl_ma86, hsl_ma97 and hsl_mc68i.
I want to use the ma_97 so I follow the advice from here. So I go were my optimal_problem code is (see code in first post). I do :
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/alic/coinhsl/lib
But when I do ./optimal_problem the linear solver still seems to be mumps because I get :
...
This is Ipopt version 3.12.9, running with linear solver mumps.
...

So hove can I select that I want the problem to be solve specifically with ma_97?

Best regards,

Alic

Joel Andersson

unread,
Feb 2, 2018, 9:48:31 AM2/2/18
to CasADi
Also, normally you don't link against the build directory. You do a "make install" step. Joel

What do you mean? (I am pretty new to cmake).


Normally you'd set CMAKE_INSTALL_PREFIX when configuring cmake (by editing CMakeCache.txt or by passing "-DCMAKE_INSTALL_PREFIX=your-install-path" to the cmake executable.
The built CasADi will be copied to this location during the "make install" step.
It's possible to link against the build directory, but that's usually not what you want to do.

So hove can I select that I want the problem to be solve specifically with ma_97?


Please keep try keep the posts on one topic. In this case, you need to pass an option to the "nlpsol" function.

        Dict opts = {{"ipopt.linear_solver", "ma97"}};                            
        Function solver = nlpsol("S","ipopt",nlp, opts);                              
 
Joel
Reply all
Reply to author
Forward
0 new messages