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++ Nios Program

Altera_Forum
Honored Contributor II
1,537 Views

Hello, 

Can anyone point me to an example of actually building a Nios-II project with cpp? I have tried many ways and it always comes down to a build error. The problem seems to be related to the alt_main.c. There must be a simple method of creating a CPP program as the documentation states everywhere that CPP is supported. I cannot find a template or an example on the website. I see where the simple socket server has a cpp implementation but it is not a full example showing the linkage with a BSP. 

Thanks,
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
448 Views

First of all you should rename as alt_main.cpp

Then, if your .cpp contain functions which are supposed to be called from .c sources, you must declare them as extern "C"
0 Kudos
Altera_Forum
Honored Contributor II
448 Views

Thanks for the reply, but I have tried that before and run into bsp build errors with it not being able to find the alt_main.c file even thought I think (???) I changed the correct makefile to build a the cpp file. 

 

Just one zipped up example of a complete project and bsp would be great if anyone has one.  

 

It just seems like it should be a no-brainer, but I just keep going around in circles. 

 

Thanks again.
0 Kudos
Altera_Forum
Honored Contributor II
448 Views

Try with others known extensions like .cc .C 

I've heard of this problem
0 Kudos
Altera_Forum
Honored Contributor II
448 Views

After much trial and error I have found a solution to building a simple CPP project. 

 

  1. Build the BSP as usual (I make sure to check the enable small lib and small drivers). 

  2. Build a NIOS-II project based on the BSP. 

  3. With the project selected, add a new file to the project. I used the "File from Template". Make sure it has the .cpp extension. Now you should have the file insterted in your project, but it will have no code inside. 

  4. Open the file for editing and insert the standard main() function, I used: 

extern "C" 

#include <stdio.h> 

#include "system.h" 

 

 

int main(void

puts("Hello World!!!"); 

return 0; 

 

Life is good again!:) 

 

 

0 Kudos
Reply