mex file generation failed

1 visualización (últimos 30 días)
Emmanuel Walter Djeutsop Sonkoua
Emmanuel Walter Djeutsop Sonkoua el 19 de Abr. de 2022
Respondida: Mark McBroom el 25 de Abr. de 2022
i'm trying to generate mex file for my project. I'm always getting the following error and i don't understand it well and also how to fix it:
[11/11] /usr/bin/xcrun -sdk macosx12.1 clang build/maci64/simulation.o build/maci64/simulation_test_data.o build/maci64/rt_nonfinite.o build/maci64/simulation_test_initialize.o build/maci64/simulation_test_terminate.o build/maci64/simulation_test.o build/maci64/_coder_simulation_test_api.o build/maci64/_coder_simulation_test_mex.o build/maci64/_coder_simulation_test_info.o build/maci64/c_mexapi_version.o -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.14 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -bundle -L"/Applications/MATLAB_R2020b.app/bin/maci64" -lmx -lmex -lmat -lc++ -Wl,-rpath,@loader_path -o simulation_test_mex.mexmaci64 -lemlrt -lcovrt -lut -lmwmathutil -Wl,-exported_symbols_list,simulation_test_mex.map
FAILED: simulation_test_mex.mexmaci64
/usr/bin/xcrun -sdk macosx12.1 clang build/maci64/simulation.o build/maci64/simulation_test_data.o build/maci64/rt_nonfinite.o build/maci64/simulation_test_initialize.o build/maci64/simulation_test_terminate.o build/maci64/simulation_test.o build/maci64/_coder_simulation_test_api.o build/maci64/_coder_simulation_test_mex.o build/maci64/_coder_simulation_test_info.o build/maci64/c_mexapi_version.o -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.14 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -bundle -L"/Applications/MATLAB_R2020b.app/bin/maci64" -lmx -lmex -lmat -lc++ -Wl,-rpath,@loader_path -o simulation_test_mex.mexmaci64 -lemlrt -lcovrt -lut -lmwmathutil -Wl,-exported_symbols_list,simulation_test_mex.map
Undefined symbols for architecture x86_64:
"_speed_control_M", referenced from:
_simulate in simulation.o
"_speed_control_initialize", referenced from:
_simulate in simulation.o
"_speed_control_step", referenced from:
_simulate in simulation.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 command i used to build and generate the mex file is shown as follow an:
codegen simulation_test -args {1,2} simulation.c -report
simulation_test.m is my matlab function and looks as follow:
function r_sim=simulation_test(KR,KI)
%#codegen
r_sim= zeros(size(0:0.01:0.25));
coder.cinclude('simulation.h');
coder.ceval('simulate',KR,KI, coder.wref(r_sim));
end
my simulation.c file looks as follow:
#include "simulation.h"
void simulate(double KR,double KI,double* r_sim)
{
speed_control_initialize();
/* Simulating the model step behavior (in non real-time) to
* simulate model behavior at stop time.
*/
while ((rtmGetErrorStatus(speed_control_M) == (NULL)) && !rtmGetStopRequested
(speed_control_M)) {
speed_control_step(KR,KI,r_sim);
}
}
now i'm not caring about the simulation result but the proper mex file generation.
I have been looking for a solution to my problem for 2 days and don't know how to move on. I tried things from Internet without success. I will appreciate your help very much.

Respuesta aceptada

Mark McBroom
Mark McBroom el 22 de Abr. de 2022
It looks like you are missing the .c file that contains the code for speed_control_initialize() and speed_control_step()
  2 comentarios
Emmanuel Walter Djeutsop Sonkoua
Emmanuel Walter Djeutsop Sonkoua el 24 de Abr. de 2022
@Mark McBroom yes you have right, i was not given my .c file were those functions are defined. So i just add it to the codegen command and the mex file is generated properly now. thanks !!!
Emmanuel Walter Djeutsop Sonkoua
Emmanuel Walter Djeutsop Sonkoua el 24 de Abr. de 2022
Now i getting my mex file crashed when i attempt to run it. And Matlab also get close.
then i checked the dump file and the abort() function seems to be called during the execution of the mex file.
as you can see in the code above i have the function declaration in simulation.h:
void simulation(double KR, double KI, double * r_sim)
the simulation results have to be save in r_sim which is initialized in the matlab function simulation_test (r_sim= zeros(size(0:0.01:0.25));)
my question is: should i initialize the pointer r_sim within my c function before writing data to that adress?
i thouht that coder.wref(r_sim) was doing that.

Iniciar sesión para comentar.

Más respuestas (1)

Mark McBroom
Mark McBroom el 25 de Abr. de 2022

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by