MATLAB Codegen Compiler Error

9 views (last 30 days)
Lawrence Costa
Lawrence Costa on 23 Mar 2018
Answered: Raghu Boggavarapu on 26 Nov 2021
Hi,
I am using attempting to convert MATLAB code to c using codegen. This works fine when I convert to mex directly. However, when I 1) use codegen to generate c files then 2) attempt to generate a mex file from the c files (using the mex command), I get the following error:
"Error using mex Undefined symbols for architecture x86_64:
[several dozen reference errors]
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)"
Is there a reason why this would work directly from the codegen command but fail when I attempt to do it step-wise? I am on a mac running High Sierra 10.13.3 with MATLAB 2017b.
Thanks for the help.
Update: Here is an example using the standard MATLAB interp1 function.
n = 130;
x = linspace(0,50,n)';
y = x.^2;
query = 27.5;
codegen interp1 -args {x,y,query}
If, instead of using interp1_mex, I attempt to use the generated c file directly, I get an error. The command
mex interp1.c
returns the error
Error using mex
Undefined symbols for architecture x86_64:
"_b_error", referenced from:
_interp1 in interp1.o
"_error", referenced from:
_interp1 in interp1.o
"_mexFunction", referenced from:
-exported_symbol[s_list] command line option
"_muDoubleScalarIsNaN", referenced from:
_interp1 in interp1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  4 Comments
Lawrence Costa
Lawrence Costa on 13 Apr 2018
Sorry for the delay. Added an example of the issue in the question body.
Walter Roberson
Walter Roberson on 13 Apr 2018
When you use mex without any options, it expects that the source you list is a function written to mex standards, for the purpose of calling the code directly from MATLAB. To compile stand-alone code for use outside of MATLAB you need to either compile outside of the mex toolchain, or else use some of the options to mex, such as -client

Sign in to comment.

Answers (1)

Raghu Boggavarapu
Raghu Boggavarapu on 26 Nov 2021
Write a new MATLAB function using coder.cinclude and coder.ceval to call the generated c function. User coder.updateBuildInfo to link the autogenerated library and also to reference the generated code directory for include paths. Now use MATLAB Coder to generate MEX for this newly written function.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!