Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

C++ Nios Program

Honored Contributor II


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. 

0 Kudos
4 Replies
Honored Contributor II

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"
Honored Contributor II

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.
Honored Contributor II

Try with others known extensions like .cc .C 

I've heard of this problem
Honored Contributor II

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!:)