I have a generated .zip file that contains generated C code from a Simulink model. The goal is to compile this code in a shared library that I can use from a .NET Core backend.
I have to compile it for both Windows as Unix systems because most of the developers are using Windows, while the server runs on Unix (and myself runs on osx).
The zip has the following structure:
optimizationModel_grt_rtw
R2019b
extern/include
rtw/c/src/
simulink/include
I also have a "script" that uses the model inside the _grt_rtw
folder.
The "script" contains one function that uses the model.
It seems I can compile it succesfully as follows:
gcc -I ./optimlib/R2019b/extern/include/ \
-I ./optimlib/R2019b/simulink/include/ \
-I ./optimlib/optimizationModel4_grt_rtw/ \
-I ./optimlib/R2019b/rtw/c/src/ \
-c -fpic src/optimumCalc.c \
-o out/optimumCalc.o
But when I try to link I get a whole lot of errors of unused references for x86_64 architecture. I'm pretty sure everything is there in the code.
Errorlogs:
Undefined symbols for architecture x86_64:
"_optimizationModel4_B", referenced from:
_calcOptimum in optimumCalc.o
"_optimizationModel4_U", referenced from:
_calcOptimum in optimumCalc.o
"_optimizationModel4_Y", referenced from:
_calcOptimum in optimumCalc.o
"_optimizationModel4_initialize", referenced from:
_calcOptimum in optimumCalc.o
"_optimizationModel4_step", referenced from:
_calcOptimum in optimumCalc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The linker command I use is the following:
gcc -dynamiclib out/optimumCalc.o -o out/optimlib.dylib
I assume there is something I'm missing with the linker command, but I can't figure it out. I also tried passing the -I parameters I passed with the first command.
I really can't find any documentation on how to compile this using gcc on systems that don't have the MATLAB/Simulink environments installed. If anyone can point me to the right direction or see what I'm missing in the linker command?
Thanks!