using std::cout in NewlibNano (nohost)

cancel
Showing results for 
Search instead for 
Did you mean: 

using std::cout in NewlibNano (nohost)

Jump to solution
244 Views
pjanco
Contributor III

Hi,

MIMXRT1062-EVK, IDE 11.3.0, SDK 2.9.1, Standard GNU C++14 and GNU C99

For using some third party library, that is originally designed for Windows/Linux, I have to reconfigure my project from C to combination of C/C++. I thing I have everything configured properly, I am using NewlibNano and I am able to compile whole project.

I am using preprocessor setting SDK_DEBUGCONSOLE=0 and my own implementation of functions _read and _write. Functions PRINTF, printf, PUTHAR, putchar, SCANF, scanf, GETCHAR, getchat are all working well and they all are calling to _write and _read and I can do with data what I need to.

But under C++, functions like std::cout<<"hello" or std::getline(std::cin, line) are not redirected to _write or _read. MCU is going memory error handler after calling them.

 

How can I redirect std::cout/std::cin to use functions _write/_read?

 

Regards,

Peter.

Tags (2)
0 Kudos
1 Solution
221 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) Is there any other trap that I should carry about after migrating the existing project from C to C++?
-- To provide the fastest possible support, I'd highly recommend you refer to the post to learn how to convert the C project to C++.
2) Is there defined any macro in IDE, that I can use to build different part of my code for "nohost" and "semihost" library?
-- No, I'm afraid it's impossible to do that.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
227 Views
pjanco
Contributor III

I already helped myself. There is explanation of problem:

I have converted my C project to C++ using integrated tool: File/New/Other/C,C++/Convert to a C,C++.

Then, I manually configure all new and empty project settings for C++ compiler. But I dismiss one thing!

File "startup_mimxrt1062.c" in project has to be renamed to "startup_mimxrt1062.cpp". I do not understand why, but it solve the problem.

 

I is there any other trap that I should carry about after migrating existing project from C to C++?

Is there defined any macro in IDE, that I can use to build different part of my code for "nohost" and "semihost" library?

0 Kudos
222 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) Is there any other trap that I should carry about after migrating the existing project from C to C++?
-- To provide the fastest possible support, I'd highly recommend you refer to the post to learn how to convert the C project to C++.
2) Is there defined any macro in IDE, that I can use to build different part of my code for "nohost" and "semihost" library?
-- No, I'm afraid it's impossible to do that.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos