Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

C++ is IMPOSSIBLE in NIOSII

Altera_Forum
Honored Contributor II
1,806 Views

Hey Everyone, 

 

After spending over 20 hours trying everything that I could, I have concluded that it is impossible to have NIOSII run C++... If you want to define your own classes you need to include the c++ library <iostream> and well, I have tried everything to add it in... when I do include this file, the NIOSII IDE finds errors in my IOSTREAM file... it actually gives syntax errors to this standard library... I think that it is hopeless... if anyone has successfully written their own classes and/or has been able to build an object oriented program in NIOSII, please let me know how you can do this.... 

if not, we should all just scrap C++.... 

 

please let me know... 

Aydin Mirzaee
0 Kudos
11 Replies
Altera_Forum
Honored Contributor II
504 Views

Ummmm.... isn&#39;t Ecos based on C++? 

 

Cheers, 

 

slacker
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

 

--- Quote Start ---  

originally posted by slacker@Nov 17 2005, 10:31 AM 

ummmm....  isn&#39;t ecos based on c++? 

 

cheers, 

 

slacker 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11034) 

--- quote end ---  

 

--- Quote End ---  

 

 

Tell me how to write a simple class and include IOSTREAM if you can...
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

That&#39;s too much work (for me) on a free advice forum [sorry!]. I&#39;d advise you to get the Ecos port, as I&#39;m quite sure that they are using classes along with iostream there, though I wouldn&#39;t know unless I browsed through its source. 

 

Cheers, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

aym35 

 

Can I recommend that you get yourself sent on a C++ course or get hold of a copy of The C++ Programming Language by Bjarne Stroustrop. 

 

It&#39;s obvious from your post that you&#39;re unfamiliar with C++ and you problems stem from this rather than being Nios specfic. 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

If you want to define your own classes you need to include the c++ library <iostream>[/b] 

--- Quote End ---  

Actually you can define your own classes without including the C++ header file <iostream>, you only need to include this if you wish to use IO Streams. 

 

Slacker is quite correct there are examples of using iostreams in the eCos port, which he is also correct is written in C++. The eCos port is available for download from this forum. 

 

As a general note whilst I&#39;m sure everyone can empathise with the frustration of being stuck, you will find that you get more help on forums and mailing lists if you restrict the tone of your posts. If you make a big bold statement like <div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

C++ is impossible in Nios II[/b] 

--- Quote End ---  

you want to be sure you&#39;re right.
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

Hi, 

I agree that my message was a pit conclusive... 

I know that IOSTREAM isn&#39;t the main header file that will include the definition of the word "class"... I have to admit that I don&#39;t know exactly what header file to use for that... but regardless, I can&#39;t define a simple class in the NIOS IDE because I get syntax errors for using the word "class"... 

is there any way to solve this???
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

aym35, 

 

I have not got a clue what you&#39;re doing to get a syntax error on class, you really should go and read up a bit about C++ before asking any more questions if you expect people to help you. 

 

Below is a very simple class 

 

class numpty 

public: 

numpty(); 

~numpty(); 

void set(int i); 

 

private: 

int data; 

}; 

 

void numpty::set(int i) 

data=i; 

return; 

 

 

I compiled this with the nios2-elf-gcc -c numpty.c and it worked fine. The -c is don&#39;t link, as this is not a complete program. However it proves the point given legal C++ the compiler handles it correctly. Now please go and read Stroustrup.
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

I use classes all the time and have had no problems. I have not required IOSTREAM in any of my applications. 

I have devised this quick test for you to see if the problem is with your Nios installation. 

Sorry if the instructions sound a bit basic but in the interests of an accurate test, I thought I should be thorough. 

 

1. Start the IDE and make sure there are no open projects in the project tree. 

2. Select File, New, C/C++Application 

3. Select one of the Altera example designs in the "SOPC Builder System:" box 

e.g. 

"C:\altera\kits\nios2\examples\verilog\niosII_cyclone_1c20\standard\std_1c20.ptf

 

4. Pick "Blank Project" as the project template and hit Finish. 

5. Highlight "blank_project_0" (or whatever it called it) in the tree and select File, New, File. 

6. Enter "Main.cpp" as the file name and hit Finish. 

7. Paste the sample code below in the file and hit Project, Build All. 

 

If this does not compile, then I suggest that there must be a problem with your Nios installation. 

If this is the case then I am sure there are others watching, better qualified to comment. 

Good Luck.. 

 

 

class MyClass 

public:  

int MyVariable; 

void MyMethod(void){}; 

}; 

 

MyClass TestClass; 

 

int main(void) 

TestClass.MyVariable = 1; 

TestClass.MyMethod(); 

return 0; 

}
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

 

--- Quote Start ---  

originally posted by aym35@Nov 18 2005, 06:46 PM 

i can&#39;t define a simple class in the nios ide because i get syntax errors for using the word "class"... 

is there any way to solve this??? 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=11048) 

--- quote end ---  

 

--- Quote End ---  

 

 

you probably wrote that in a file with a .c extension, 

or in a header that gets included in a C module. 

Start over in a file that has a .cpp extension and it will work. 

no extra header required. 

 

Cheers, Roger
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

C++ works fine for my project.  

We have now about 400 modules and 20 larger classes.  

C++ and NIOS works. 

We had problems when we mixed .c and .cpp modules. The compiler acts different depending on the file extentions. 

 

Karsten 

 

Ps: we used good old fgte, fput, fprintf ..... for io at a serial interface
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

as stated above the problem is probably with your file extension it should be *.cpp  

if you use the *.c the c compiler will be invoked and the word "class" won&#39;t be recognize
0 Kudos
Altera_Forum
Honored Contributor II
504 Views

I realize this is an old thread but if I remember correctly you had to define your C++ header files with the extension .hpp for the IDE to treat them appropriately. Stupid yes but it&#39;s the truth. The other option is to modify the file type associations for the project. Also this may have been fixed recently.

0 Kudos
Reply