Help using MatLab coder.

1 view (last 30 days)
Reynaldo
Reynaldo on 21 Apr 2012
Commented: vcmorini on 19 Jul 2017
Hey! I am trying to use the MatLab coder but I keep getting the same error over and over again. No matter what changes I make, the same error keeps appearing. Here is the MatLabcode I am trying to convert to C++:
function [result] = test(x,h)
result =x+h;
This is a really easy code that the coder should be able to compile without any hesitation but still it is not able to make the conversion. I have declared the datatypes on the coder project window. I am using MatLab version R2011a. I have also configured my Visual Studio compiler with MatLab using mex -setup. This is the error I am getting (in the Target Build Log):
1 Setting environment for using Microsoft Visual Studio 2010 x64 tools.
2
3 Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
4 Copyright (C) Microsoft Corporation. All rights reserved.
5
6 ### Compiling test.c
7 cl -DUSE_RTMODEL /Od /Oy- -DMODEL=test -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32 -W4 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x05000000 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_MT -MT /wd4996 test.c
8 test.c
9 ### Compiling test_initialize.c
10 cl -DUSE_RTMODEL /Od /Oy- -DMODEL=test -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32 -W4 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x05000000 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_MT -MT /wd4996 test_initialize.c
11 test_initialize.c
12 ### Compiling test_terminate.c
13 cl -DUSE_RTMODEL /Od /Oy- -DMODEL=test -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32 -W4 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x05000000 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_MT -MT /wd4996 test_terminate.c
14 test_terminate.c
15 ### Compiling rt_nonfinite.c
16 cl -DUSE_RTMODEL /Od /Oy- -DMODEL=test -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32 -W4 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x05000000 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_MT -MT /wd4996 rt_nonfinite.c
17 rt_nonfinite.c
18 ### Compiling rtGetNaN.c
19 cl -DUSE_RTMODEL /Od /Oy- -DMODEL=test -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32 -W4 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x05000000 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_MT -MT /wd4996 rtGetNaN.c
20 rtGetNaN.c
21 ### Compiling rtGetInf.c
22 cl -DUSE_RTMODEL /Od /Oy- -DMODEL=test -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -nologo -GS -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32 -W4 -D_WINNT -D_WIN32_WINNT=0x0500 -DNTDDI_VERSION=0x05000000 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -D_MT -MT /wd4996 rtGetInf.c
23 rtGetInf.c
24 ### Linking ...
25 C:\PROGRA~1\MATLAB\R2011a\sys\perl\win32\bin\perl C:\PROGRA~1\MATLAB\R2011a\rtw\c\tools\mkvc_lnk.pl test.lnk test.obj test_initialize.obj test_terminate.obj rt_nonfinite.obj rtGetNaN.obj rtGetInf.obj
26 link /RELEASE /INCREMENTAL:NO /NOLOGO -subsystem:console,5.02 kernel32.lib ws2_32.lib mswsock.lib advapi32.lib libcpmt.lib @test.lnk @test_ref.rsp -out:C:\Users\Pixel\DOCUME~1\PRUEBA~2\test.exe
27 LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
28 C:\Users\Pixel\DOCUME~1\PRUEBA~2\test.exe : fatal error LNK1120: 1 unresolved externals
29 NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.EXE"' : return code '0x460'
30 Stop.
31 The make command returned an error of 2
32 'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
33 operable program or batch file.
34
I hope I can find a solution to this problem. Thank you very much for your help!
  1 Comment
vcmorini
vcmorini on 19 Jul 2017
I am having the same problem. MinGW compiles fine.

Sign in to comment.

Answers (1)

Titus Edelhofer
Titus Edelhofer on 21 Apr 2012
Hi,
when compiling to an executable you need to provide a main function (a file containing
void main()
{
/* call the MATLAB coder code */
}
Don't have MATLAB available on this machine, but somewhere on the MATLAB coder settings you specify a file containing the main function ...
Titus

Community Treasure Hunt

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

Start Hunting!