Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,008 Views

C++ compiler errors

I am new to C++/ucos II. 

 

Compiling a simple test C++ program gets the following error messages: 

 

error: 'alt_irq_register' was not declared in this scope 

error: invalid conversion from 'void*' to 'OS_STK*' 

error: initializing argument 3 of 'INT8U OSTaskCreateExt(void (*)(void*), void*, OS_STK*, INT8U, INT16U, OS_STK*, INT32U, void*, INT16U)' 

error: invalid conversion from 'void*' to 'OS_STK*' 

error: initializing argument 3 of 'INT8U OSTaskCreateExt(void (*)(void*), void*, OS_STK*, INT8U, INT16U, OS_STK*, INT32U, void*, INT16U)' 

 

Any help will be appreciated.
0 Kudos
6 Replies
Altera_Forum
Honored Contributor I
85 Views

Having the source to look at (or at least the correct segment) would be helpful. 

 

First problem alt_irq_register not declared is you probably need the appropriate header file, the second problem look at what you have in the third argument position on your OSTaskCreateExt and either type-cast it to OS_STK* or define it properly.
Altera_Forum
Honored Contributor I
85 Views

Thank you, anakha 

 

I forgot to mention that the same source is compiler error free using C. I got the error messages after renaming the program from .c to .cpp. 

 

Below is the relevant source codes:  

 

----------- 

alt_irq_register(UART_IRQ,&context_uart,IsrUart ); 

 

OSTaskCreateExt(task1, 

NULL, 

(void *)&task1_stk[TASK_STACKSIZE-1], 

TASK1_PRIORITY, 

TASK1_PRIORITY, 

task1_stk, 

TASK_STACKSIZE, 

NULL, 

0); 

 

 

OSTaskCreateExt(task2, 

NULL, 

(void *)&task2_stk[TASK_STACKSIZE-1], 

TASK2_PRIORITY, 

TASK2_PRIORITY, 

task2_stk, 

TASK_STACKSIZE, 

NULL, 

0); 

----------
Altera_Forum
Honored Contributor I
85 Views

The GCC behaves different for c and c++ code. This is caused by the different file extentions. To make some library code like OS code run under c++ you have to declare it properly as "pure" c code. This is also required for some other hardware interface stuff. 

 

for example: 

 

 

#ifdef 

__cplusplus 

 

extern  

"C" 

 

#endif 

 

 

 

 

// c specific stuff  

 

 

 

#ifdef 

__cplusplus 

 

#endif 

 

 

Altera_Forum
Honored Contributor I
85 Views

Thank you, Karsten

Altera_Forum
Honored Contributor I
85 Views

Hello, 

 

I'm working on a µC/OS II project using some C++. 

Compiling the example project "Hello MicroC/OS-II" works and simply changing the file extension from .c to .cpp or changing the target type in the makefile will still, in contrast to shacler, let project compile. But the Nios II build environment seems to have a problem to link the object files: 

 

make: *** [Cpp_Test.elf] Error 1 Cpp_Test C/C++ Problem 

 

and in the console output: 

 

[...] Cpp_Test_bsp/HAL/src/alt_main.c:154: undefined reference to `main' 

 

Any hints on how to fix this problem? According to the documentation C++ should work. 

 

Thanks in advance!
Altera_Forum
Honored Contributor I
85 Views

Sorry for pushing but the handover date is approaching :-S

Reply