how do I get debug_printf to work?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how do I get debug_printf to work?

1,573 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sravet on Wed Jan 16 21:49:50 MST 2013
The adc_buzzer example runs fine on my custom LPC1768 based board, including semihosting output to the console.  I am trying to bring this semihosting over to another project, which was imported to lpcxpresso from the mbed online compiler.  This code already has printf statements in it, which execute but don't produce output on the console.  I'm pretty sure that this is because the mbed library already implements printf using its own USB backchannel.  Ok fine.

So I took a look at adc_buzzer which uses debug_printf and friends.  In my project I copied over debug.h and debug.c from adc_buzzer.  They get compiled and linked in but I still get a linker error that _debug_printf is unresolved.  Here is the makefile output:


Building file: ../debug.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -DDEBUG -D__NEWLIB__ -DTOOLCHAIN_GCC_CR -DTARGET_LPC1768 -D__CODE_RED -DCPP_USE_HEAP -I"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2" -I"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/lib_small_printf_m3/inc" -I"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/fixedpoint" -I"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed" -I"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768" -I"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR" -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -fno-exceptions -mcpu=cortex-m3 -mthumb -MMD -MP -MF"debug.d" -MT"debug.d" -o "debug.o" "../debug.c"
Finished building: ../debug.c

Building target: illmot_proto2_1_2.axf
Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/lib_small_printf_m3/Lib" -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/CMSISv1p30_LPC17xx/Debug" -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2" -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/fixedpoint" -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed" -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768" -L"/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR" -Xlinker -Map="illmot_proto2_1_2.map" -Xlinker --gc-sections -mcpu=cortex-m3 -mthumb -T "/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR/LPC1768.ld" -o "illmot_proto2_1_2.axf"  ./fixedpoint/fixed_func.o  [COLOR=Red]./debug.o[/COLOR] ./main.o ./pattern.o ./semaphore.o  /Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR/cmsis_nvic.o /Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR/system_LPC17xx.o /Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR/core_cm3.o /Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/mbed/LPC1768/GCC_CR/startup_LPC17xx.o -llib_small_printf_m3 -lCMSISv1p30_LPC17xx -lmbed
./main.o: In function `main':
/Users/sravet/Documents/LPCXpresso_5.0.14/workspace/illmot_proto2_1_2/Debug/../main.cpp:44: undefined reference to `[COLOR=Red]_debug_printf(char const*, ...)[/COLOR]'
collect2: ld returned 1 exit status
make: *** [illmot_proto2_1_2.axf] Error 1

If I do objdump on debug.o I see that symbol:

[FONT=Courier New]% arm-none-eabi-objdump -t debug.o

debug.o:     file format elf32-littlearm

SYMBOL TABLE:
00000000 l    df *ABS*00000000 debug.c
00000000 l    d  .text00000000 .text
00000000 l    d  .data00000000 .data
00000000 l    d  .bss00000000 .bss
00000000 l    d  .bss.debug_write_buf00000000 .bss.debug_write_buf
00000000 l     O .bss.debug_write_buf00000052 debug_write_buf
00000000 l    d  .bss.debug_buf_read_index00000000 .bss.debug_buf_read_index
00000000 l     O .bss.debug_buf_read_index00000001 debug_buf_read_index
00000000 l    d  .bss.debug_buf_write_index00000000 .bss.debug_buf_write_index
00000000 l     O .bss.debug_buf_write_index00000001 debug_buf_write_index
00000000 l    d  .text._debug_printf_flush00000000 .text._debug_printf_flush
00000000 l    d  .text._debug_putchar00000000 .text._debug_putchar
00000000 l    d  .text._debug_printf00000000 .text._debug_printf
00000000 l    d  .bss.debug_read_buf00000000 .bss.debug_read_buf
00000000 l     O .bss.debug_read_buf00000016 debug_read_buf
00000000 l    d  .text._debug_getstr00000000 .text._debug_getstr
00000000 l    d  .text._debug_puts00000000 .text._debug_puts
00000000 l    d  .debug_info00000000 .debug_info
00000000 l    d  .debug_abbrev00000000 .debug_abbrev
00000000 l    d  .debug_loc00000000 .debug_loc
00000000 l    d  .debug_aranges00000000 .debug_aranges
00000000 l    d  .debug_ranges00000000 .debug_ranges
00000000 l    d  .debug_line00000000 .debug_line
00000000 l    d  .debug_macinfo00000000 .debug_macinfo
00000000 l    d  .debug_str00000000 .debug_str
00000000 l    d  .debug_frame00000000 .debug_frame
00000000 l    d  .comment00000000 .comment
00000000 l    d  .ARM.attributes00000000 .ARM.attributes
00000000 g     F .text._debug_printf_flush000000f6 _debug_printf_flush
00000000         *UND*00000000 __write
00000000 g     F .text._debug_putchar000000c6 _debug_putchar
00000000 g     F .text._debug_printf0000002c _debug_printf
00000000         *UND*00000000 printf_format_nofloat
00000000 g     F .text._debug_getstr0000008a _debug_getstr
00000000         *UND*00000000 __read
00000000         *UND*00000000 small_strlen
00000000 g     F .text._debug_puts00000034 _debug_puts
00000000  w    F .text._debug_printf_flush000000f6 __CR_SEMIHOST[/FONT]

So I don't understand why this symbol is not resolved.  Can someone help me out here?
0 Kudos
Reply
1 Reply

1,278 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sravet on Mon Oct 07 20:10:53 MST 2013
Well I finally found the answer to this question.  The problem is calling C from C++.  The names of the functions are mangled and can't be resolved at link time.  The answer is to add the usual:

#ifdef CPLUSPLUS
extern "c" {

}
#endif

around the function declarations.
0 Kudos
Reply