stdio.h

I use Eclipse and yagarto gcc

when i build my project using printf or sprintf function i get the

errors shown below. I have included stdio.h file in my project using

#include “stdio.h”.

It seems I cant access functions in the stdio library.

The project builds successfully when sprintf or printf is removed

/* *********************************************************

Header files & Function declarations

********************************************************* */

#include “lpc214x.h”

#include “uart.h”

#include “stdio.h”

void Initialize(void);

void feed(void);

void IRQ_Routine (void) attribute ((interrupt(“IRQ”)));

void FIQ_Routine (void) attribute ((interrupt(“FIQ”)));

void SWI_Routine (void) attribute ((interrupt(“SWI”)));

void UNDEF_Routine (void) attribute ((interrupt(“UNDEF”)));

void delay_ms(unsigned ms)

{

int i,j;

for(i=0;i<ms;i++)

for(j=0;j<6659;j++);

}

int main(void)

{

int val=0;

char s[30];

Initialize();

SCS = 0x03;

uart0_init(9600);

PINSEL1 |=0x10000000;

AD0CR= 0x01210608;

while(1)

{

AD0CR |= 0x01000000;

while((AD0DR3 & 0x80000000)== 0);

val = ((AD0DR3 >> 6) & 0x03FF);

sprintf(s,“Analog(AD0.3): %d \r”,val);

uart0_puts(s);

delay_ms(200);

}

}

/**********************************************************

Initialize

**********************************************************/

#define PLOCK 0x400

void Initialize(void) {

PLLCFG=0x24;

feed();

PLLCON=0x1;

feed();

while(!(PLLSTAT & PLOCK)) ;

PLLCON=0x3;

feed();

MAMCR=0x2;

MAMTIM=0x4;

VPBDIV=0x02;

}

void feed(void)

{

PLLFEED=0xAA;

PLLFEED=0x55;

}

void IRQ_Routine (void) {

while (1) ;

}

void FIQ_Routine (void) {

while (1) ;

}

void SWI_Routine (void) {

while (1) ;

}

void UNDEF_Routine (void) {

while (1) ;

}

You did not show your error messages, but the most probable cause is that either or both the header file OR library file are not in your search path?

error message:

Make -k all

.assembling

arm-elf-as -ahls -mapcs-32 -o crt.o crt.s > crt.lst

.compiling

arm-elf-gcc -I./ -c -fno-common -O0 -g main.c

…linking

arm-elf-ld -v -Map main.map -Tdemo2148_blink_flash.cmd -o main.out crt.o main.o

GNU ld version 2.17

main.o: In function `main’:

C:\Documents and Settings\Administrator\workspace\a2d/main.c:39: undefined reference to `sprintf’

Since the error occured during the linking phase, it seems that whatever library you wanted to link to was not in the search path?

You’re invoking ld directly, which means it won’t be linking in anything you don’t explicitly tell it to — you don’t specify libc (or any other libraries) on the linker command line, so there’s no ‘sprintf’ implementation available.

(Including the stdio.h header just tells the compiler what functions exist and how to call them. In order to get the actual functions themselves into the final program, the corresponding .o or library must be included when you link.)

Often it’s easier to use cc for linking. It just calls ld, but it passes useful default options, like crt0.o and libc and libgcc (if needed on that platform) and so on.

I realize that you are using the NXT LPC2148, but the latest revision of my tutorial “Using Open Source Tools for AT91sam7 Cross Development” has a new section devoted to libraries. Here’s a link:

http://www.atmel.com/dyn/resources/prod … source.zip

The information about including libraries is at page 111.

Cheers,

Jim Lynch