Problems when building generated C-code on Windows

Hello,

I am on Windows and currently trying to use the code generated in Matlab by ocp.generate_c_code(). I am using Visual Studio 2019 for the development in C.
I have linked the libraries in the “lib” folder. When i try to build the project, i receive the following error messages:

libacados.lib(timing.c.obj) : error LNK2019: unresolved external symbol gettimeofday referenced in function acados_toc
libacados.lib(sim_collocation_utils.c.obj) : error LNK2019: unresolved external symbol __ms_vsnprintf referenced in function snprintf.constprop.0
libblasfeo.lib(d_blas3_lib4.c.obj) : error LNK2019: unresolved external symbol ___chkstk_ms referenced in function blasfeo_hp_dgemm_tn

It seems there are some problems with linking libraries, but I don’t know which.

  1. From what I know, “gettimeofday” is a Unix specific function and does not exist on Windows.
  2. The other two errors seem to be caused by some mismatch in MinGW versions. I have installed acados for use with Matlab as explained in the documentation. There is only one version of MinGW on my path.

Does someone know where the problem may be?
Any help is welcome.

Greetings,
Christian

Hi Christian,

For what part exactly are you using Visual Studio?
I think both the acados core library and all MEX functions should be compiled with the same compiler.

Note: There is an alternative workflow for use with MSVC documented, since last week: Installation — acados documentation

With MSVC, the first if branch should be used in the timings file, as far as I understand. acados/timing.c at master · acados/acados · GitHub

Best,
Jonathan

I am using Visual Studio as I am trying to compile it into a DLL and the existing code for that works with the MSVC compiler.

I tried the new workflow with MSVC, but didn’t get it to compile the examples.
I have tried both MSVC 2017 and 2019 but i am running into the same errors as described in the original question plus multiple linker errors like:

libblasfeo.lib(d_lapack_lib4.c.obj) : error LNK2019: unresolved external symbol "printf" in function "blasfeo_hp_dgeqrf.part.3".
libblasfeo.lib(d_aux_ext_dep.c.obj) : error LNK2001: unresolved external symbol "printf".
libblasfeo.lib(i_aux_ext_dep_lib.c.obj) : error LNK2001: unresolved external symbol "printf".
libblasfeo.lib(d_blas3_diag_lib4.c.obj) : error LNK2001: unresolved external symbol "printf".

This seems to be caused by the fact that these static libaries are compiled with a visual studio version older than 2015 after which the function “printf” like many other stdio functions was defined inline.
These errors could be solved by linking “legacy_stdio_definitions.lib”.

FYI: for CMake with Visual Studio 2019, the architecture gets passed with the -A flag. This should be corected in the docs for the new workflow.

cmake -G "Visual Studio 16 2019" -A x64 -DBLASFEO_TARGET=GENERIC -DACADOS_INSTALL_DIR=.. -DBUILD_SHARED_LIBS=OFF ..

The problem with the “gettimeofday” seems not to be in timing.c but in the library libacados.lib where acados_toc is referenced. Even without defining MEASURE_TIMINGS and uing the dummy functions, this error occurs.

Best,
Christian

Hi Christian,

I’ve been using the MSVC workflow as well, without any problems. Are you sure that you did a clean build? Do you still get these same errors if you first completely remove the lib and the build folders? Thus you’d ensure that the blasfeo static libraries are built with the right compiler.

Cheers,
Caspar