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.
So, after installing MSYS2 64 bit and gcc using its package management system pacman, the following instructions will work as expected:
Input:
!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
res =
struct with fields:
p1: 5.5000
p2: 1234
p3: 12345678
st =
-279
For anybody trying to reprodue this, I nave removed mex references from shrlibsample.c