You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
fatal error C1083: Cannot open source file: '..\..\..\..\Program Files\MATLAB\R2017a\rtw\c\src\common\rt_main.c': No such file or directory [Using Code Generation in Simulink]
17 views (last 30 days)
Show older comments
I am trying to build my Simulink model using Visual Studio 2012 c++ compiler which is building just fine. However, included in the project are two .c files, namely:
rt_main.c
rt_logging.c
And when I try to build the model in Visual Studio 2012, it gives me the error that is in the title. In the directory '..\..\..\..\Program Files\MATLAB\R2017a\rtw\c\src\common\rt_main.c': I cannot find a file named rt_main.c, but I can find one named rt_main.cpp. Same for the rt_logging.c file. I've tried changing names either places without luck.
1) Why are .c files included in the project, when I have specificed in the Code Generation Options that the system target file is grt.tlc [Create Visual C/C++ Solution File for Simulink Coder] with c++ language?
2) How can I make Simulink build using the rt_main.cpp file?
If I uncheck the box "Generate Code Only" in Configuration Parameters -> Code Generation -> Build Process, it gives me the errors:
1>------ Build started: Project: SimulinkModelDLL, Configuration: Debug x64 ------
1>Build started 15-03-2021 12:01:44.
1>InitializeBuildStatus:
1> Creating "x64\Debug\SimulinkModelDLL.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> rt_main.c
1>c1 : fatal error C1083: Cannot open source file: '..\..\..\..\Program Files\MATLAB\R2017a\rtw\c\src\common\rt_main.c': No such file or directory
1> rt_logging.c
1>c1 : fatal error C1083: Cannot open source file: 'rt_logging.c': No such file or directory
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.12
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
10 Comments
Rasmus Visgaard
on 15 Mar 2021
Correct. It builds just fine in Simulink, but if I attempt to build it in VS2012, it gives me the said error.
Fangjun Jiang
on 15 Mar 2021
Okay, I think you can "generate code" fine in Simulink but not "build", because you had those "build" errors in MATLAB Command window.
It surprised me that I found only rt_main.c in R17b and R18b folders but not rt_main.cpp file.
Where did you find the file and can you open it to look at the "abstract" at the begining of the file?
Rasmus Visgaard
on 15 Mar 2021
Funny, because it's the other way around here. I can find the rt_main.cpp but not the rt_main.c. The folder I found it in is the same folder that VS is looking for the rt_main.c :
C:\Program Files\MATLAB\R2017a\rtw\c\src\common
Abstract:
/*
* Copyright 2012-2015 The MathWorks, Inc.
*
* File: rt_main.c
*
* Abstract:
*
* A real-time main that runs generated Simulink Coder code under most
* operating systems. Based on the definition of MULTITASKING, a single-task
* or multitask step function is employed.
*
* This file is a useful starting point for creating a custom main when
* targeting a custom floating point processor or integer micro-controller.
*
* Alternatively for ERT targets, you can generate a sample ert_main.c file
* with the generated code by selecting the "Generate an example main program"
* option. In this case, ert_main.c is precisely customized to the
* model requirements.
*
* Required Defines:
*
* MODEL - Model name
* NUMST - Number of sample times
*
*/
Fangjun Jiang
on 15 Mar 2021
Noted "* File: rt_main.c"?? not rt_main.cpp. Check the date for the file to see if it matches the date of other original files.
Fangjun Jiang
on 16 Mar 2021
restore the original files (or try just rename the .cpp files to .c) and try again. CPP application can with with C files.
Rasmus Visgaard
on 16 Mar 2021
I tried to rename .cpp files to .c and tried again. I got the following error:
I have renamed some directories for proprietary reasons to XXXXX.
Build started 16-03-2021 13:29:46.
1>Project "C:\XXXXXX\Bladed\SimulinkModelDLL_grt_rtw\msvc\SimulinkModelDLL.vcxproj" on node 2 (Build target(s)).
1>InitializeBuildStatus:
Creating "x64\Debug\SimulinkModelDLL.unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\CL.exe /c /IC:\XXXXXX\Bladed /I"C:\Program Files\MATLAB\R2017a\simulink\include\sf_runtime" /IC:\XXXXXX\Bladed\SimulinkModelDLL_grt_rtw /I"C:\Program Files\MATLAB\R2017a\extern\include" /I"C:\Program Files\MATLAB\R2017a\simulink\include" /I"C:\Program Files\MATLAB\R2017a\rtw\c\src" /I"C:\Program Files\MATLAB\R2017a\rtw\c\src\ext_mode\common" /Zi /nologo /W2 /WX- /Od /D WIN32 /D _DEBUG /D _CONSOLE /D MODEL=SimulinkModelDLL /D NUMST=1 /D NCSTATES=0 /D HAVESTDIO= /D RT= /D USE_RTMODEL= /D MAT_FILE=1 /D INTEGER_CODE=0 /D MT=0 /D CLASSIC_INTERFACE=0 /D ALLOCATIONFCN=0 /D ONESTEPFCN=1 /D TERMFCN=1 /D MULTI_INSTANCE_CODE=0 /D TID01EQ=0 /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"x64\Debug\\" /Fd"x64\Debug\vc110.pdb" /Gd /TC /errorReport:prompt "..\..\..\..\Program Files\MATLAB\R2017a\rtw\c\src\common\rt_main.c" "..\..\..\..\Program Files\MATLAB\R2017a\rtw\c\src\rt_logging.c"
rt_main.c
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtgmath.h(111): warning C4602: #pragma pop_macro : 'new' no previous #pragma push_macro for this identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(28): error C2061: syntax error : identifier 'acosf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(28): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(28): error C2061: syntax error : identifier 'asinf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(29): error C2061: syntax error : identifier 'atanf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(29): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(29): error C2061: syntax error : identifier 'atan2f'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(29): error C2061: syntax error : identifier 'ceilf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(30): error C2061: syntax error : identifier 'cosf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(30): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(30): error C2061: syntax error : identifier 'coshf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(30): error C2061: syntax error : identifier 'expf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(31): error C2061: syntax error : identifier 'fabsf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(31): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(31): error C2061: syntax error : identifier 'floorf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(31): error C2061: syntax error : identifier 'fmodf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(32): error C2061: syntax error : identifier 'frexpf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(32): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(32): error C2061: syntax error : identifier 'ldexpf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(32): error C2061: syntax error : identifier 'logf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(33): error C2061: syntax error : identifier 'log10f'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(33): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(33): error C2061: syntax error : identifier 'modff'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(33): error C2061: syntax error : identifier 'powf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(34): error C2061: syntax error : identifier 'sinf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(34): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(34): error C2061: syntax error : identifier 'sinhf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(34): error C2061: syntax error : identifier 'sqrtf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(35): error C2061: syntax error : identifier 'tanf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(35): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(35): error C2061: syntax error : identifier 'tanhf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(37): error C2061: syntax error : identifier 'acosl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(37): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(37): error C2061: syntax error : identifier 'asinl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(38): error C2061: syntax error : identifier 'atanl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(38): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(38): error C2061: syntax error : identifier 'atan2l'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(38): error C2061: syntax error : identifier 'ceill'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(39): error C2061: syntax error : identifier 'cosl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(39): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(39): error C2061: syntax error : identifier 'coshl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(39): error C2061: syntax error : identifier 'expl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(40): error C2061: syntax error : identifier 'fabsl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(40): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(40): error C2061: syntax error : identifier 'floorl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(40): error C2061: syntax error : identifier 'fmodl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(41): error C2061: syntax error : identifier 'frexpl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(41): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(41): error C2061: syntax error : identifier 'ldexpl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(41): error C2061: syntax error : identifier 'logl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(42): error C2061: syntax error : identifier 'log10l'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(42): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(42): error C2061: syntax error : identifier 'modfl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(42): error C2061: syntax error : identifier 'powl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(43): error C2061: syntax error : identifier 'sinl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(43): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(43): error C2061: syntax error : identifier 'sinhl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(43): error C2061: syntax error : identifier 'sqrtl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(44): error C2061: syntax error : identifier 'tanl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(44): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(44): error C2061: syntax error : identifier 'tanhl'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(46): error C2061: syntax error : identifier 'abs'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(46): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(48): error C2061: syntax error : identifier 'acos'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(48): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(48): error C2061: syntax error : identifier 'asin'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(49): error C2061: syntax error : identifier 'atan'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(49): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(49): error C2061: syntax error : identifier 'atan2'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(49): error C2061: syntax error : identifier 'ceil'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(50): error C2061: syntax error : identifier 'cos'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(50): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(50): error C2061: syntax error : identifier 'cosh'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(50): error C2061: syntax error : identifier 'exp'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(51): error C2061: syntax error : identifier 'fabs'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(51): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(51): error C2061: syntax error : identifier 'floor'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(51): error C2061: syntax error : identifier 'fmod'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(52): error C2061: syntax error : identifier 'frexp'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(52): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(52): error C2061: syntax error : identifier 'ldexp'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(52): error C2061: syntax error : identifier 'log'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(53): error C2061: syntax error : identifier 'log10'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(53): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(53): error C2061: syntax error : identifier 'modf'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(53): error C2061: syntax error : identifier 'pow'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(54): error C2061: syntax error : identifier 'sin'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(54): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(54): error C2061: syntax error : identifier 'sinh'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(54): error C2061: syntax error : identifier 'sqrt'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(55): error C2061: syntax error : identifier 'tan'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(55): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(55): error C2061: syntax error : identifier 'tanh'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(57): error C2061: syntax error : identifier 'hypot'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(57): error C2059: syntax error : ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(57): error C2061: syntax error : identifier 'hypotf'
rt_logging.c
Generating Code...
1>Done Building Project "C:\XXXXX\Bladed\SimulinkModelDLL_grt_rtw\msvc\SimulinkModelDLL.vcxproj" (Build target(s)) -- FAILED.
Build FAILED.
Time Elapsed 00:00:00.58
Rasmus Visgaard
on 19 Mar 2021
Some further insight:
I tried changing the Simulink option to generate c-code, and I can both generate the code and build it using visual studio 2012 without problems. The issue seems to be, that if I want Simulink to generate c++ code, it's trying to locate rt_main.c and compile it as c++ for some reason. Changing the name of rt_main.c to rt_main.cpp does not help either, as it is, for another reason unknown, trying to locate the rt_main.c file which no longer exists.
Answers (0)
See Also
Categories
Find more on Embedded Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)