The question was originated by an improper installation of system wide mingw-w64, I did mistakenly installed a 32 bit version (msys/mingw).
My other proposed solution, was working just because I was using the MATLAB Add-on provided mingw-w64 compiler, something limited if one intends to develop C libraries to be later interfaced with MATLAB mex files.
The following link can be helpful for those anew in this context .
So, after installing MSYS2 64 bit and gcc using its package management system pacman, the following instructions will work as expected:
!gcc -c shrlibsample.c
!gcc -o shrlibsample.dll shrlibsample.o -s -shared -Wl,--subsystem,windows,--out-implib,"shrlibsample.lib"
mex -v -g myAddStructByRef.c shrlibsample.lib
struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290;
[res,st] = myAddStructByRef(struct)
Output: C Struct: p1: 4.000000 p2: 7 p3: -290
Calculated sum: -279.000000
struct with fields:
For anybody trying to reprodue this, I nave removed mex references from shrlibsample.c