[En-Nut-Discussion] C++ and Uart

Olof Tångrot olof.tangrot at telia.com
Tue May 10 18:12:11 CEST 2005


It's probably C++ name mangling that does not play well with C function 
names, try

#ifdef __cplusplus
extern "C"
{
#include <stdio.h>
}
#endif


----- Original Message ----- 
From: "Stephan Uhle" <stephan.uhle at alcatel.de>
To: <en-nut-discussion at egnite.de>
Sent: Tuesday, May 10, 2005 5:04 PM
Subject: [En-Nut-Discussion] C++ and Uart


> Hi everybody,
>
> I'm a relative newbie to ethernut and just trying to build up a serial
> communication between my Charon II Board and my PC.
> When I use C everything works fine but when using C++ I get the following
> linker-error:
>
> serial.o(.text+0x1e): In function `_cxx_main_()':
> : undefined reference to `freopen(char const*, char const*, __iobuf*)'
>
> This is my program:
>
> #include <dev/uartavr.h>
> #include <stdio.h>
>
>
> #include <cpp/nutcpp.h>
>
>
> int main(void)
> {
>   NutRegisterDevice(&devUart0, 0, 0);
>   freopen("uart0","w",stdout);
>   printf("Hello world\n");
>
>
>   for(;;);
> }
>
> and this is the way I compile:
>
> $ avr-gcc -mmcu=atmega128 -Os -Wall -Wstrict-prototypes -I~/nut/include -c
> serial.cpp
>
> and link...
>
> $ avr-gcc serial.o  -mmcu=atmega128
> -Wl,--defsym=main=0,-Map=serial.map,--cref -L~/nut/lib ~/nut/lib/nutinit.o
> -lnutos -lnutcrt -lnutdev -lnutfs -lnutnet -lnutos -lnutpro -lnutcrt
> -lnutcpp -o serial.elf
>
> I'm using the cvs - version of April 19th 2005 on Redhat 9.
>
> Did I just forget to add a specific library or header-file?
>
>
> Thanks in advance,
>
> Stephan
> -- 
>
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion 




More information about the En-Nut-Discussion mailing list