0

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:

codegen simulation_test -args {1,2} simulation.c -report

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.

  • 1
    The error message says that the symbols (functions, variables) `_speed_control_M`, `_speed_control_initialize` and `_speed_control_step` are not defined anywhere in the inputs to the build command. That means you are missing a source file or a library in your build command. No idea what you're missing, because I don't know what those missing symbols are. – Cris Luengo Apr 19 '22 at 17:41
  • Did you try instead of using simulation.c file use simulation mex file "codegen simulation_test -args {1,2} simulation_mex -report". You can create simulation_mex using mex simulation.c in matlab. (You might need -client option for mex) – Ali Özgür Argunşah Apr 19 '22 at 17:57
  • simulation_mex does not exist in my computer – Walter Sonkoua Apr 19 '22 at 19:07
  • @CrisLuengo _speed_control_M, _speed_control_initialize and _speed_control_step are define in simulation.h. Hier the declarations in simulation.h : extern void speed_control_initialize(void); extern void speed_control_step(double KR,double KI,double* r_sim); extern void speed_control_terminate(void); /* Real-time Model object */ extern RT_MODEL_speed_control_T *const speed_control_M; – Walter Sonkoua Apr 20 '22 at 07:32
  • @WalterSonkoua Those are the declarations, not the definitions. The definitions are missing. Definition is where the body of the function is, the code that is run when you call the function. – Cris Luengo Apr 20 '22 at 15:10
  • @CrisLuengo the implementation of these declarations are in my file simulation.c – Walter Sonkoua Apr 20 '22 at 19:39
  • Weird! In that case you might have a problem with the configuration of your system. Do you happen to have an M1 Mac? If so, maybe `simulation.c` was compiled for your native architecture (arm64) and then linker command (which is the bit you show here) tries to link the x86_64 libraries that come with MATLAB to your arm64 `simulation.o` object file, and fails. The linker command carries the `-arch x86_64` flag, which would be needed for MATLAB binaries. You should check to see if your compiler command also carries that same flag. – Cris Luengo Apr 20 '22 at 20:21
  • yes i'm working on MAC OS, my processor is Intel core i5. @CrisLuengo please how to check my compiler command and modified it? Matlab use m the c compiler clang. I don't know how. I think you right, may be you are talking of this command wich failed: undefined error -arch x86_64 -mmacosx-version-min=10.14 -Wl and i think it is what you are talking about – Walter Sonkoua Apr 22 '22 at 07:43
  • @CrisLuengo you were write, i was missing a file. now it works my mex file generation – Walter Sonkoua May 11 '22 at 20:43

0 Answers0