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

Migrate C Application to C++

Honored Contributor II

Hello everyone, 

is there a documentation how to migrate a running Nios II application 

(uses generated BSP with HAL drivers for DE2-70 Board SD card and Video interface) 

from C to C++ ? 


Best regards  

0 Kudos
2 Replies
Honored Contributor II


I solved the problem after a while. 


I renamed my source file containing the main function to Mainfile.cpp 

and did a refresh on the Eclipse Projekt. 


I used the BSP Editor in Eclipse to set Enable_c_plus_plus 

Then I generated the new BSP and rebuilt the whole Project. 


The next issue is an error from the generated Altera_UP_SD_Card_Avalon_Interface.h 

which reads as: 





# include <stddef.h> 

# include <alt_types.h> 

# include <sys/alt_dev.h> 


# ifdef __cplusplus 

extern "C" 

# endif /* __cplusplus */ 


# ifndef bool 

typedef enum e_bool { false = 0, true = 1 } bool; 

# endif 



This certainly can not compile with c++ (strange enough the extern "C" construct encourages a c++ compatibility which obviously has never been tested ). 

So I went through the generated source files and my source code calling them and replaced 


bool -> BOOL 

false -> FALSE 

true -> TRUE 


Rebuilding the BSP I got: 

Symbol NULL could not be resolved 


So I replaced 


NULL -> 0 


With that the BSP did build without errors 


I defined the application project properties 

C/C++ General -> Paths and symbols -> Symbols 


so the extern "C" constructs with the generated files get visible. 


Next I got error from  

nread = write(console_io_fi,str,strlen(str)); 

which is defined in 



_READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte )); 


I replaced the# include <unistd.h> 

with: # include "sys/unistd.h" 


and then got to an error: 

Function '__builtin_stwio' could not be resolved 


This seemed to be complicated but finally I found a solution at: 

Which is really simple (but creepy) 

Go to the Window menue in main menu bar.  


C/C++ -> Code Analysis 

Scroll down a bit on the right-hand column.  

Turned the option: Function cannot be resolved. from "error" to "warning" 


Important reminder, after applying the change of the setting,  

don’t forget to close the Eclipse IDE and reopen it.  

I noticed that without restarting the Eclipse IDE, the new setting is not effective.  

After restarting the Eclipse IDE, you will notice that the two semantic error messages above are no longer reported as error. 


This solution works but kills any expedient error if once you do not provide a necessary function. 



0 Kudos
Honored Contributor II

C and C++ maybe same in some basic syntax, but i found it more troublesome when convert from a C to C++ when involve more object oriented elements, i mean when in application layer . :)

0 Kudos