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

c++ version of twothreads example

Altera_Forum
Honored Contributor II
1,094 Views

Hi Forum, 

 

I have been developing applications using eCos and the NiosII IDE for a while now, and wish to develop in c++. I started with the twothreads example and had it up and running in no time. I simply changed the file name from twothreads.c to twothreads.cxx to see what would happen. It compiled OK, but would not run properly. The line of execution appeared to get stuck before the threads got a chance to run (or something). 

 

Is there something fundamental that I am missing here? 

 

Do I have to indicate the c functions using some construction like: 

 

extern "c" { void function_name(void);} 

 

Or is there a more basic problem? 

 

Thanks in advance for any help provided. 

 

peter
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
389 Views

Hi Peter, 

 

Try adding the word "externC" before the cyg_user_start function in twothreads.cxx, like this: 

 

/* we install our own startup routine which sets up threads */ externC void cyg_user_start(void) {  diag_printf(" Entering\n");  ...  ... } 

 

This should help the linker recognise that you have provided a copy of cyg_user_start, otherwise it will link in the default version. I think externC stops the C++ name-mangler from changing the function name into one that won't link with the code that expects cyg_user_start to be in a module written in C. 

 

Mike
0 Kudos
Altera_Forum
Honored Contributor II
389 Views

Thanks Mike, 

 

This appears to solved the problem. 

 

Peter
0 Kudos
Reply