Hi @Maciek ,
The toolbox has an option to specify for your model a different .mex file than the default one (the one that follows the <model_name>Config.mex naming convention).
In hardware settings:

This way you can use the same mex file across multiple models that can be further referenced in a main model. And you need to make sure that the main model is using the same mex file - either by setting the option as above screenshot or by following the naming convention. We have in the toolbox a simple example with model refs: NXP_MBDToolbox_IMXRT1xxx\IMXRT_Examples\imxrt117x\model_ref: evkmimxrt1170_sldemo_mdlref_counter.slx will be referenced multiple times in evkmimxrt1170_sldemo_mdlref_basic.slx
The evkmimxrt1170_sldemo_mdlref_counter.slx has set in the Board Configuration File the .mex file of the main model.
So you can have just one .mex file shared amongst multiple models and for model refs the shared mex should be also used in the main model.
I hope this answers your questions.
BR,
Alexandra