Why do I get Linker errors while building a Simulink model to dll file

Why do I get linker errors as below (seems that the compile can't recognize the trunc function)while building a Simulink model to dll for Canape. And my compile environment is based on Windows 10 / MATLAB R2016b / Microsoft Windows SDK 7.1.
### Generating code into build folder: D:\localhome\taol\Documents\MATLAB\untitled_cnp_rtw
Overflow occurred. This originated from 'untitled/ClutchOverloadDetection/Clutch Overload/IfAction_Subsystem/Friction Energy Calculation/IfAction/Add1'.
Component:Simulink | Category:BlockwarningSuppress this warning
### Invoking Target Language Compiler on untitled.rtw
### Using System Target File: D:\Programme\MATLAB\R2016b\rtw\c\canape\cnp.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
### Caching model source code
...............................................................................
.........................
### Writing header file untitled.h
### Writing header file untitled_types.h
### Writing header file untitled_private.h
### Writing header file rtwtypes.h
.
### Writing header file builtin_typeid_types.h
### Writing header file multiword_types.h
### Writing header file zero_crossing_types.h
### Writing header file rtGetNaN.h
### Writing source file rtGetNaN.c
### Writing header file rt_nonfinite.h
.
### Writing source file rt_nonfinite.c
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing source file untitled.c
### Writing header file rtmodel.h
### Writing source file untitled_data.c
### Writing header file rt_defines.h
.
### TLC code generation complete.
### Generating TLC interface API.
### Creating ASAP2 file: untitled.a2l
Warning: Skipping non-reference parameter: BreakpointsData
### Indenting ASAP2 file.
.
### Processing Template Makefile: D:\Programme\MATLAB\R2016b\rtw\c\canape\cnp_msdll.tmf
### Creating untitled.mk from D:\Programme\MATLAB\R2016b\rtw\c\canape\cnp_msdll.tmf
### Building untitled: .\untitled.bat
D:\localhome\taol\Documents\MATLAB\untitled_cnp_rtw>call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\SetEnv" /x86 /release /xp 2>devnull.2 1>devnull.1
Microsoft (R) Program Maintenance Utility Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
untitled.c
untitled.c(147) : warning C4013: 'trunc' undefined; assuming extern returning int
rtGetInf.c
rtGetNaN.c
rt_logging.c
rt_matrx.c
rt_nonfinite.c
rt_printf.c
untitled_data.c
cnp_main.c
xcpBasic.c
xcpServer.c
rt_sim.c
rtwlog.c
cnpcomm.cpp
nlapml.cpp
timer.cpp
cnpenvin.c
cnpenvout.c
### Linking ...
Creating library Release/untitled.lib and object Release/untitled.exp
untitled.obj : error LNK2019: unresolved external symbol _trunc referenced in function _untitled_output
Release\untitled.dll : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\link.EXE"' : return code '0x460'
Stop.
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
Error(s) encountered while building "untitled"

 Accepted Answer

You are using Sdk7.1 compiler which does not implement some of the C99 functions. VS2012 did not include it either.
In your release your options are VS2013 professional, vs2015 professional, vs2017 professional, or MinGW 4.9.2. None of those VS releases are free to use, and the community / express editions were not supported. MinGW was free but by now it might be difficult to find that release.

4 Comments

Hello Walter,
Thanks for your answer! I have install the MinGW 4.9.2 and also setup it as the compiler at MATLAB command window.But when I try to build my model to dll based on MinGW 4.9.2.The error is as below still could not implement some of the C99 functions,seems that still call the Microsoft Windows SDK 7.1 (C) compiler.So do you have any idea about this new issue.Thanks a lot!
>> mex -setup
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different C compiler, select one from the following:
MinGW64 Compiler (C) mex -setup:C:\Users\taol\AppData\Roaming\MathWorks\MATLAB\R2016b\mex_C_win64.xml C
MinGW64 Compiler (C) mex -setup:D:\Programme\MATLAB\R2016b\bin\win64\mexopts\mingw64.xml C
Microsoft Windows SDK 7.1 (C) mex -setup:D:\Programme\MATLAB\R2016b\bin\win64\mexopts\winsdk-7.1_c.xml C
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
*************************************************************************************************************************
Build process:
### Starting Real-Time Workshop build procedure for model: cluovld
### Generate model description file: cluovld.ini
20 file(s) in 5.15 sec generated.
Code Generation 2 1
Elapsed: 11 sec
### Generating code into build folder: D:\localhome\taol\Documents\MATLAB\cluovld_cnp_rtw
### Invoking Target Language Compiler on cluovld.rtw
### Using System Target File: D:\Programme\MATLAB\R2016b\rtw\c\canape\cnp.tlc
### Loading TLC function libraries
### Initial pass through model to cache user defined code
### Caching model source code
...............................................................................
...............................
### Writing header file cluovld.h
### Writing header file cluovld_types.h
### Writing header file cluovld_private.h
### Writing header file rtwtypes.h
.
### Writing header file builtin_typeid_types.h
### Writing header file multiword_types.h
### Writing header file zero_crossing_types.h
### Writing header file rtGetNaN.h
### Writing source file rtGetNaN.c
### Writing header file rt_nonfinite.h
.
### Writing source file rt_nonfinite.c
### Writing header file rtGetInf.h
### Writing source file rtGetInf.c
### Writing source file cluovld.c
### Writing header file rtmodel.h
### Writing source file cluovld_data.c
### Writing header file rt_defines.h
.
### TLC code generation complete.
### Generating TLC interface API.
### Creating ASAP2 file: cluovld.a2l
Warning: Skipping non-reference parameter: BreakpointsData
### Indenting ASAP2 file.
.
### Processing Template Makefile: D:\Programme\MATLAB\R2016b\rtw\c\canape\cnp_msdll.tmf
### cluovld.mk which is generated from D:\Programme\MATLAB\R2016b\rtw\c\canape\cnp_msdll.tmf is up to date
### Building cluovld: .\cluovld.bat
.
D:\localhome\taol\Documents\MATLAB\cluovld_cnp_rtw>call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\SetEnv" /x86 /release /xp 2>devnull.2 1>devnull.1
Microsoft (R) Program Maintenance Utility Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
cluovld.c
cluovld.c(165) : warning C4013: 'trunc' undefined; assuming extern returning int
cluovld_data.c
rtGetInf.c
rtGetNaN.c
rt_nonfinite.c
rt_sim.c
### Linking ...
Creating library Release/cluovld.lib and object Release/cluovld.exp
cluovld.obj : error LNK2019: unresolved external symbol _trunc referenced in function _cluovld_output
Release\cluovld.dll : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\link.EXE"' : return code '0x460'
Stop.
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
### Creating HTML report file cluovld_codegen_rpt.html
Error(s) encountered while building "cluovld"
you might have to adjust the toolchain settings. I do not know how to do that for your release.

Sign in to comment.

More Answers (0)

Tags

Asked:

on 4 Aug 2020

Commented:

on 14 Aug 2020

Community Treasure Hunt

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

Start Hunting!