Getting compilation error with generated c code with Emlrt functions

조회 수: 7 (최근 30일)
Manish
Manish 2024년 6월 4일
답변: Samay Sagar 2024년 8월 21일
I used the matlab code generator and generated the c code from my project.
The generated code i was compiling using gcc compiler and everything was find but al tast i am getting the undefined reference error for following function which is looks like dfetching the matlab library which i not have.
The functions in which i am getting error declarations i found in emlrt.h file but definitions i am not able to get.
The Errors are below
53: undefined reference to `emlrtAlias'
54: undefined reference to `emlrtDestroyArray'
allIn':
69: undefined reference to `emlrtCheckBuiltInR2012b'
72: undefined reference to `emlrtImportArrayR2015b'
73: undefined reference to `emlrtDestroyArray'
lIn':
90: undefined reference to `emlrtAlias'
91: undefined reference to `emlrtDestroyArray'
lOut':
106: undefined reference to `emlrtCreateNumericArray'
107: undefined reference to `emlrtMxGetData'
111: undefined reference to `emlrtAssign'
131: undefined reference to `emlrtAliasP'
151: undefined reference to `emlrtEnterRtStackR2012b'
152: undefined reference to `emlrtLeaveRtStackR2012b'
The above snaps is a part of errors.
Please provide me the solution for that errors.

답변 (1개)

Samay Sagar
Samay Sagar 2024년 8월 21일
Hi Manish,
I understand that you are encountering errors while trying to compile C code generated from MATLAB.
The error logs suggest that the generated C code is trying to link against MATLAB's runtime libraries, but these libraries are not available in your current setup.
This typically happens when the necessary MATLAB runtime libraries are not included in your compilation process.
Here is how you can address this issue
1. Use the Generated Batch File:
  • MATLAB Coder or the “codegen” command generates a batch file (.bat on Windows or a shell script on Linux/Mac) that contains the necessary commands and flags to compile the C files into binaries. This batch file is tailored to your specific project and includes paths to the required MATLAB runtime libraries.
  • Locate this batch file in your code generation output directory and execute it to compile your project. This should resolve the undefined reference errors by ensuring all necessary libraries are linked.
2. Configurations for Executable Generation: When using “codegen” to generate C code, you can configure the project to create a standalone executable. This involves setting the appropriate build configurations. You can refer the following documentation to generate executable for your MATLAB code:
For more information about Code Generation, you can refer the following documentation: https://www.mathworks.com/help/overview/code-generation.html
Hope this helps!

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by