Problem with code generation on windows platform

Hi guys!

I am trying to generate C-code in Matlab (R2016b, Windows 10, MinGW-Compiler) using the generate_c_code method of the ocp-object in the minimal_example_ocp example. All the files are generated and compiled when creating the ocp-object. Also the generate_c_code method runs without erros but as mentioned in the docs the compilation cannot be done directly in Windows. Therefore I use cygwin and run the make command from inside the c_generated_code folder. However, it seems that the compiler as problems finding the linked libraries libacados.lib,libhpipm.lib and libblasfeo. It returns the following error code:

/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/…/…/…/…/x86_64-pc-cygwin/bin/ld: -lacados cannot be found
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/…/…/…/…/x86_64-pc-cygwin/bin/ld: -lhpipm cannot be found
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/…/…/…/…/x86_64-pc-cygwin/bin/ld: -lblasfeo cannot be found

When checking env I can see that the LD_LIBRARY_PATH is set correctly to …/acados/examples/acados_matlab_octave/getting_started/…/…/…/lib. The content if the folder are the three .lib-files mentioned above.

I appriciate any hints helping get past this issue!

Hi Michael,

first of all, welcome to the forum! :tada:

It is a while ago that I tried this.
In general, LD_LIBRARY_PATH is irrelevant on Windows.
Instead you should add the path to the PATH variable in the GUI.

Also, I think you should always use the same compiler on Windows, the one we tested and recommended is mingw from MATLAB, but I guess you already did that…
https://docs.acados.org/installation/index.html#windows-for-use-with-matlab

What do you mean by “checking env” on Windows?

Cheers!

Hi,

Thank you for the fast reply.

What I was trying to do with cygwin, was using a Linux-like environment within Windows. I somehow managed to solve the issue now. Within the cygwin environment I could check for which kind of library-files the linker is looking. It was interesting to see that the output was the following:

/cygdrive/d/hub/external/acados/lib/libacados.dll.a 
/cygdrive/d/hub/external/acados/lib/acados.dll.a
/cygdrive/d/hub/external/acados/lib/libacados.a
/cygdrive/d/hub/external/acados/lib/acados.lib
/cygdrive/d/hub/external/acados/lib/libacados.dll 
/cygdrive/d/hub/external/acados/lib/acados.dll
/cygdrive/d/hub/external/acados/lib/acados.lib

As you can see it never checks for libacados.lib. I solved the issue by copying the .lib files and renaming them without the prefix lib. Then it was possible to compile the generated c-code using the following matlab code.

MODEL_OBJ = ['pendulum_model/pendulum_expl_ode_fun.o ' ...
    'pendulum_model/pendulum_expl_vde_forw.o'];

OCP_OBJ = 'acados_solver_pendulum.o';
SIM_OBJ = 'acados_sim_solver_pendulum.o';
OBJ = strjoin({MODEL_OBJ, OCP_OBJ, SIM_OBJ},' ');
EX_OBJ= 'main_pendulum.o';


INCLUDE_PATH = [ACADOS_ROOT '/include'];
LIB_PATH = [ACADOS_ROOT '/lib'];

CASADI_MODEL_SOURCE =['pendulum_expl_ode_fun.c ' ...
    'pendulum_expl_vde_forw.c'];

%% casadi_fun:
cd pendulum_model\
system(['gcc -fPIC -g -c ' CASADI_MODEL_SOURCE]);
cd ..

%% main:
system(['gcc -fPIC -g -c main_pendulum.c ' ...    	
    '-I ' INCLUDE_PATH '/blasfeo/include/ ' ...
	'-I ' INCLUDE_PATH '/hpipm/include/ ' ...
	'-I ' INCLUDE_PATH ' '...
	'-I ' INCLUDE_PATH '/acados/']);
 
%% ocp_solver:
system(['gcc -fPIC -g -c acados_solver_pendulum.c ' ...    	
    '-I ' INCLUDE_PATH '/blasfeo/include/ ' ...
	'-I ' INCLUDE_PATH '/hpipm/include/ ' ...
	'-I ' INCLUDE_PATH ' '...
	'-I ' INCLUDE_PATH '/acados/']);
 
%% sim_solver:
system(['gcc -fPIC -g -c acados_sim_solver_pendulum.c ' ...    	
    '-I ' INCLUDE_PATH '/blasfeo/include/ ' ...
	'-I ' INCLUDE_PATH '/hpipm/include/ ' ...
	'-I ' INCLUDE_PATH ' '...
	'-I ' INCLUDE_PATH '/acados/']);

%% example:
system(['gcc -fPIC -g -o main_pendulum ' EX_OBJ ' ' OBJ ' ' ...    
	'-L ' LIB_PATH ' -lacados -lhpipm -lblasfeo -lm ' ...
    '-I ' INCLUDE_PATH '/blasfeo/include/ ' ...
	'-I ' INCLUDE_PATH '/hpipm/include/ ' ...
	'-I ' INCLUDE_PATH ' '...
	'-I ' INCLUDE_PATH '/acados/']);

%% bundled_shared_lib: casadi_fun ocp_solver sim_solver
system(['gcc -fPIC -g -shared ' OBJ ' -o libacados_solver_pendulum.lib ' ...    
	'-L ' LIB_PATH ' -lacados -lhpipm -lblasfeo -lm']) 

%% ocp_shared_lib: casadi_fun ocp_solver
system(['gcc -fPIC -g -shared ' OCP_OBJ ' ' MODEL_OBJ ' '...
    '-o libacados_ocp_solver_pendulum.lib ' ...    
	'-L ' LIB_PATH ' -L ' LIB_PATH '/acados '...
    '-lacados -lhpipm -lblasfeo -lm']) 
 
%% sim_shared_lib: casadi_fun sim_solver
system(['gcc -fPIC -g -shared ' SIM_OBJ ' ' MODEL_OBJ ' '...
    '-o libacados_sim_solver_pendulum.lib ' ...    
	'-L ' LIB_PATH ' -L ' LIB_PATH '/acados '...
    '-lacados -lhpipm -lblasfeo -lm']) 

I will let you know when I tested the compiled functions. Won’t be able to do that today anymore.