MATLAB Codegen Compiler Error

조회 수: 9 (최근 30일)
Lawrence Costa
Lawrence Costa 2018년 3월 23일
답변: Raghu Boggavarapu 2021년 11월 26일
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
Lawrence Costa
Lawrence Costa 2018년 4월 13일
Sorry for the delay. Added an example of the issue in the question body.
Walter Roberson
Walter Roberson 2018년 4월 13일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Raghu Boggavarapu
Raghu Boggavarapu 2021년 11월 26일
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.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by