Forum Discussion
Altera_Forum
Honored Contributor
20 years agoC++ is IMPOSSIBLE in NIOSII
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 Mirzaee11 Replies
- Altera_Forum
Honored Contributor
Ummmm.... isn't Ecos based on C++?
Cheers, slacker - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by slacker@Nov 17 2005, 10:31 AM ummmm.... isn'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...
- Altera_Forum
Honored Contributor
That's too much work (for me) on a free advice forum [sorry!]. I'd advise you to get the Ecos port, as I'm quite sure that they are using classes along with iostream there, though I wouldn't know unless I browsed through its source.
Cheers, - slacker - Altera_Forum
Honored Contributor
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's obvious from your post that you'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'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're right. - Altera_Forum
Honored Contributor
Hi,
I agree that my message was a pit conclusive... I know that IOSTREAM isn't the main header file that will include the definition of the word "class"... I have to admit that I don't know exactly what header file to use for that... but regardless, I can'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??? - Altera_Forum
Honored Contributor
aym35,
I have not got a clue what you'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'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. - Altera_Forum
Honored Contributor
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; } - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by aym35@Nov 18 2005, 06:46 PM i can'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
- Altera_Forum
Honored Contributor
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 - Altera_Forum
Honored Contributor
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't be recognize