After struggling for a while I found the answer myself. Apparently I had to properly write a rtwmakecfg.m file and put it in my mex folder.
How can I separate source files and mex files in a simulink s-function library for use with simulink coder?
3 views (last 30 days)
Riccardo Spica on 8 Nov 2013
I am trying to create a simulink library which mainly contains some s-function blocks. I would also like to use this library to create some model files that I would then build with the simulink coder and run in external mode.
I managed to create the library, build and run the model in external mode. Indeed everything seems to work well unless I put the source (.cpp) files and the .mexa64 (I am on a linux machine) files in different folders, even if both the source and the mex folders are in the path.
It seems to me that if the source is in a different path than the mex files, during the build simulink does not compile the source files of the s-functions and then in the linking phase it complains that it doesn't find the corresponding object (.o) file. Indeed looking at the building process it is clear that simulink compiles the s-function sources and produces the corresponding objects if (and only if) they are in the same folder of the mex files.
I have also tried to force simulink to compile the source files by manually adding them in the source file box of the code generation option panel but doing so generates a bunch of "multiple definition" errors.
I don't understand why there sould be a relation between source and mex since (as far as I understood) mex files are only used in normal simulation mode. Indeed I can delete the mex files once the compilation is over and the executable would keep on working fine.
On the other hand I have seen that in the shipped c++ examples and especially in the one of the counter, not only source and mex files are in different folders but also it seems that neither one of them is in the path!?
Thanks and regards!