mex file generation failed
5 views (last 30 days)
Show older comments
Emmanuel Walter Djeutsop Sonkoua
on 19 Apr 2022
Answered: Mark McBroom
on 25 Apr 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.
0 Comments
Accepted Answer
Mark McBroom
on 22 Apr 2022
It looks like you are missing the .c file that contains the code for speed_control_initialize() and speed_control_step()
2 Comments
More Answers (1)
Mark McBroom
on 25 Apr 2022
See the bottom of this page for instructions on how to use a source code debugger on C Mex Functions.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!