Using math.h functions in Simulink S-function builder

Hi,
I'm trying to create a design with some S-Functions blocks coded in C. I'm using the S-Function Builder and I trying to use some math.h functions. I included math.h in my libraries, but these functions are not referenced.
These are the errors that I got:
Writing library for code.mexw32
PATH\code_wrapper.obj .text: undefined reference to '_lroundf'
PATH\code_wrapper.obj .text: undefined reference to '_fabsf'
I would be glad if you can tell me what is the problem.
Thank you.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 22일

0 개 추천

You have not linked against the math library. On OS-X and Linux systems, that would be by adding the option "-lm" to the mex command line (the name of the library on those systems is "m").
My reading suggests that if you were using Visual Studio that it would already have the math library built in to the standard libraries. Are you possibly using MinGW ?

댓글 수: 5

Hi Walter, thank you for your response.
No, I'm using the inbuilt S-Function Builder at Simulink:
https://fr.mathworks.com/help/simulink/sfg/s-function-builder-dialog-box.html
What is strange for me is that some math.h functions are well defined : fabs() for instance.
So I think the math library is linked. But, as shown in the error that I got, the fabsf() and lroundf() aren't defined.
I'm using the lcc-win32, "-lm" options doesn't works with it. I'm trying to install MinGW but I have some problems with Matlab 2015b.
Unfortunately I do not know much about lcc-32.
When I look at https://pubs.usgs.gov/sir/2008/5065/USGS_AR_LowflowGUI/LFArk1_mcr/LFArk1_BEB1E7AFA58B476C104CA972EFDF3CB1/compopts.bat which indicates it sets up for using lcc with the C math library, I do not see any explicit math library.
Pedro Bernardes
Pedro Bernardes 2017년 2월 23일
편집: Pedro Bernardes 2017년 2월 23일
It usually contains every C99 libraries: http://www.cs.virginia.edu/~lcc-win32/C-Tutorial.pdf
But I don't know the reason why when I call the mex compiler it doesn't links to the library.

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

카테고리

도움말 센터File Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

질문:

2017년 2월 22일

편집:

2017년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by